Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I originally post this issue on #1979260: Automatically populate the author default value with the current user comment #12, and after the instructions given by effulgentsia and linclark I can confirm that it is not possible to set the node's author when posting via HAL, however the request return a 201 and the node is created with Anonymous as author.
Another inconsistence that I've found is that my only user (uid 1) has not uuid assigned on the users table.
I have attached several screen shots that I hope help to understand what is happening.
Comment | File | Size | Author |
---|---|---|---|
rest-post-hal-4.jpg | 125.21 KB | altrugon | |
rest-post-hal-3.jpg | 131.09 KB | altrugon | |
rest-post-hal-2.jpg | 127.59 KB | altrugon | |
rest-post-hal-1.jpg | 125.25 KB | altrugon | |
rest-get-hal.jpg | 151.87 KB | altrugon |
Comments
Comment #1
effulgentsia CreditAttribution: effulgentsia commentedThat's a bug being worked on in #2050843: Users 0 and 1 are created without a UUID
From #1979260-18: Automatically populate the author default value with the current user:
Yeah, it would be good for us to add a test for that once this support request is answered.
Comment #2
anavarreI can confirm that behavior:
$ curl --include --request POST --user root:root --basic --header 'Content-type: application/hal+json' http://head.local/entity/node --data-binary '{"_links":{"type":{"href":"http://head.local/rest/type/node/page"}}, "title":[{"value":"Page posted as UID 1"}], "uid":[{"target_id":"1"}]}'
Which returns:
So, node 10 should have UID 1 as the node author but it's UID 0 (anon) instead:
Comment #3
fenda CreditAttribution: fenda commentedI'm also unable to figure out how to set a node author via the REST API. I've attempted the same POST syntax as shown in above comments in various combinations.
Comment #4
MartijnBraam CreditAttribution: MartijnBraam commentedThanks for the report.
I followed your steps and this seems to be working with the patch from this issue applied: #2180109: Change the current_user service to a proxy
Comment #5
anavarreJust got to this issue again and I also confirm it now works fine. Thanks for the pointer @MartijnBraam!