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.


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.

| improve this answer | |
  • 406 Not Acceptable: Missing required argument node – ted.strauss Jun 18 '12 at 16:35
  • look at which tests? – ted.strauss Jun 18 '12 at 16:35
  • Kyle, what test were you referreing to in your answer and are there such tests for a D7 Services beginner to take advantage of? – sisko Nov 25 '13 at 9:38
  • The tests are in the test folder for the services module. – Kyle Browning Nov 27 '13 at 17:24

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.