3

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 2

1

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.

4
  • 406 Not Acceptable: Missing required argument node Jun 18, 2012 at 16:35
  • look at which tests? Jun 18, 2012 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, 2013 at 9:38
  • The tests are in the test folder for the services module. Nov 27, 2013 at 17:24
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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