I wrote a REST plugin for posting data to my Drupal site, When I send JSON data from browser it is returning the error {readyState: 4, responseText: "{"error":"Syntax error"}", responseJSON: Object, status: 400, statusText: "Bad Request"} but it is working fine in Postman. What might be the issue?

The data I am send is {"name" : "user", "pass" : "userpass"}

I am also adding the following headers in request.

"Content-Type", 'application/json'
"Accept", 'application/json'
  • 'content-type', 'application/hal+json' and Accept is not necessary – No Sssweat Aug 22 '16 at 5:46
  • what language does your plugin use? – No Sssweat Aug 22 '16 at 5:47
  • @NoSssweat - I tried 'application/hal+json' now I am getting '{readyState: 4, responseText: "{}", responseJSON: Object, status: 415, statusText: "Unsupported Media Type"}'. Could you please explain what is language here? – Unnikrishnan Aug 22 '16 at 5:48
  • 1
    You can use postman to generate your code – No Sssweat Aug 22 '16 at 5:52
  • 1
    @NoSssweat - Thanks! it's working perfectly as expected, I used code from postman as you suggested. Could you please tell me how I can vote for your answer. – Unnikrishnan Aug 22 '16 at 7:19

You can use Postman to generate your code

enter image description here

Click here to change code language

enter image description here

  • Does that postman also ring twice? Also, any hint / suggestions about where to find something to learn more about what you can do with it? Like a video tutorial or some kind of step by step docu? – Pierre.Vriens Aug 28 '16 at 16:48

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.