Skip to main content

You have been working hard on getting comments being added (POST) through REST in Drupal 8.  However, now you are seeing the following Assigning the wrong user against a new comment - and most likely the new comment is being assigned to the site admin.  

The error here is related to the _embedded uuid.

What to do

You need to check that you have the correct uuid for both the entity_id and the uid

  • entity_id - "http://example.local/rest/relation/comment/comment/entity_id";
  • uid - "http://example.local/rest/relation/comment/comment/uid"

Where...

{
...
  "_embedded": {
    "http://example.local/rest/relation/comment/comment/entity_id": [{
        "uuid": [{"value": "8795cd5d-d223-4cad-9373-605c8ffac10f"}]
      }],
    "http://example.local/rest/relation/comment/comment/uid": [{
        "uuid": [{"value": "a8c95c05-4546-4c7b-def5-fed7a4c5beca"}]
      }]
  }
}

Want to see the request body in full - go to Drupal 8 REST POST comments

Testing this, I found that you can change the entity_id value (in this example 2) then the line becomes

"http://example.local/relation/comment/comment/entity_id":{"href":"http://example.local/node/2?_format=hal_json"}

so the entity_id is set to the correct node.nid value that you want to comment posted too.  If the uuid points to a different entity_id then the comment will be assigned to entity of the uuid in the _embedded area.  

This also applies to the "http://example.local/rest/relation/comment/comment/uid"

Related articles

Andrew Fletcher04 Apr 2025
Managing .gitignore changes
When working with Git, the .gitignore file plays a critical role in controlling which files and folders are tracked by version control. Yet, many developers are unsure when changes to .gitignore take effect and how to manage files that are already being tracked. This uncertainty can lead to...
Andrew Fletcher26 Mar 2025
How to fix the ‘Undefined function t’ error in Drupal 10 or 11 code
Upgrading to Drupal 10.4+ you might have noticed a warning in their code editor stating “Undefined function ‘t’”. While Drupal’s `t()` function remains valid in procedural code, some language analysis tools — such as Intelephense — do not automatically recognise Drupal’s global functions. This...
Andrew Fletcher17 Mar 2025
Upgrading to PHP 8.4 challenges with Drupal contrib modules
The upgrade from PHP 8.3.14 to PHP 8.4.4 presents challenges for Drupal 10.4 websites, particularly when dealing with contributed modules. While Drupal core operates seamlessly, various contrib modules have not yet been updated to accommodate changes introduced in PHP 8.4.x. This has resulted in...