4

Trying to create a node page through web-service.But returns 415 Unsupported media type

This is how I have done

enter image description here

enter image description here

2
  • I think we need more information. What modules do you have installed on the site? Depending on the rest module installed, this could require hal+json as the content type. The answer below mentions a Core issue that was fixed several months before Drupal 8.0.0 release. Are you using a supported Drupal 8.0.x release?
    – mradcliffe
    Dec 21, 2015 at 19:01
  • I am using drupal 8.0.1. I have used the default rest module. Just used rest ui for ui. Thats all
    – Aparna
    Jan 1, 2016 at 11:59

2 Answers 2

2

Here is some example raw data you should be sending (don't send it as form data):

{
  "type":[{"target_id":"article"}],
  "title":[{"value":"Hello World"}]
}

You do not need to send the Accept header, because that no longer matters because of the _format=json query string. And in this case, when successful, it will return a 201 so you can disregard the _format query string.

The POST to ?q=entity/node is correct, but don't forget to send an X-CSRF-Token header with a value that can be retrieved here: ?q=rest/session/token

1
  • I come from Google and had problems with hal+json or hal_json all the time. After I switched everything to pure JSON and removed _links from my data payload, everything works now.
    – qräbnö
    Oct 4, 2019 at 14:12
1

You are apparently trying to send form-data encoded values? If you claim the send json, then you actually need to send a valid json structure. This is a service, not a form.

Create a new in the UI that looks like one that you want to create, then access it using GET through rest with the same format. Adjust that, e.g. remove the ID and UUID and then use that as the template/value to POST.

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.