Skip to main content

Assigning the wrong user against a new comment using REST

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.

401 Forbidden - Access denied on creating field 'uid'

The magically descriptive error 401 Forbidden "message": "Access denied on creating field 'uid'.".  You probably can sense the love I have for this error.  This was a painful error that took a little while to resolve.  First off I also had this error display as:

415 Unsupported Media Type - REST POST comments

If you are like me you probably have searched for clues to and found little... particularly when confronted by the errors as you unravel how this works.  Okay a slight exaggeration, there are snipets of info that people have solved this annoying issue in  making comments work in Drupal 8 REST services.

Drupal 8 REST POST comments

For others that have spent countless hours getting this to work and are struggling... in particular assigning the correct user to the comment - this is how I achieved the correct outcome.

The outline below is for usage via Postman and DHC (Restlec Client)... once working here then testing done and ready to apply to your app or however you are using this.

Set up

Set accept to hal+json

sample:

POST request

Subscribe to comments