I am trying to create a node using the rest service. I am hitting /myendpoint/node
using a post. My header is application/json
. I am not sure what I need to post as the data.
2 Answers
Something along the lines of this, &node[title]=testnode&node[type]=story&node[field_test][0][value]=testtting
Also, if you are ever unaware of what to send, just look at the tests.
-
-
-
Kyle, what test were you referreing to in your answer and are there such tests for a D7 Services beginner to take advantage of?– siskoNov 25, 2013 at 9:38
-
This might give you some ideas: https://gist.github.com/affc9864487bb1b9c918.
I assume you have Content-Type: application/json
in your header.
Example curl call with session authentication:
curl -X POST "http://example.com/endpoint/node" -H "Content-Type: application/json" -H "Accept: application/json" -H "Cookie: {session_name}={session_id}" -d '{"type":"story","title":"Test Title","body":"Test Body"}'
Basically you have to post data in JSON format, that maps to the fields of the content type you want to create. If you have custom fields it is just a bit more tricky. See: http://drupal.org/node/1354202.