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 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...
Andrew Fletcher20 Feb 2025
Handling duplicate records in Drupal
Duplicate records in Drupal can cause significant issues, particularly when they lead to integrity constraint violations in the database. These errors often occur due to duplicate UUIDs in the `node` table, which can result from programmatic imports, migrations, or unintended database...
Andrew Fletcher17 Feb 2025
The overlooked challenge of migration updates in Drupal projects
When working on Drupal migrations, developers often assume that adding a new field to the process section will seamlessly update existing content. However, unless explicitly handled, Drupal’s migration system does not automatically apply changes to previously migrated records. This oversight can...