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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

effulgentsia’s picture

Another inconsistence that I've found is that my only user (uid 1) has not uuid assigned on the users table.

That'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:

I did also check several Test modules but wasn't able to find a sample where the uid was specified.

Yeah, it would be good for us to add a test for that once this support request is answered.

anavarre’s picture

I 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:

HTTP/1.1 201 Created
Date: Fri, 20 Dec 2013 13:51:51 GMT
Server: Apache/2.4.6 (Ubuntu)
X-Powered-By: PHP/5.5.3-1ubuntu2.1
Location: http://head.local/entity/node/10
Cache-Control: must-revalidate, no-cache, post-check=0, pre-check=0, private
X-UA-Compatible: IE=edge,chrome=1
Content-language: en
Last-Modified: Fri, 20 Dec 2013 13:51:51 GMT
ETag: "1387547511"
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8

So, node 10 should have UID 1 as the node author but it's UID 0 (anon) instead:

mysql> SELECT nid,title,uid FROM `node_field_data` WHERE nid=10;
+-----+----------------------+-----+
| nid | title                | uid |
+-----+----------------------+-----+
|  10 | Page posted as UID 1 |   0 |
+-----+----------------------+-----+
1 row in set (0.00 sec)
fenda’s picture

I'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.

MartijnBraam’s picture

Issue summary: View changes
Status: Active » Closed (fixed)
Parent issue: » #2180109: Change the current_user service to a proxy

Thanks 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

anavarre’s picture

Just got to this issue again and I also confirm it now works fine. Thanks for the pointer @MartijnBraam!