user3648392
user3648392

Reputation: 11

Drupal 8.x POST (create) node via REST doesn't work

I am working with Drupal 8.0 alpha 11. I've been able to follow the Drupal guides for REST services:

POST for creating content entities (https://drupal.org/node/2098511) and the related guides, GET on content entities and GET on Views-generated lists

"GET"s work great, but I haven't been able to get any "POST" to work (I've posted the issue on the drupal.org site, too).

I've tested POST for both a basic page and my own content entity and neither works. I've tried a lot of variations, including removing "entity" from the url as per the recent changes in Drupal 8, but the POST still does not work. I'm using Postman in Chrome for testing and again, I can "GET" a basic page and my own content entity just fine, but with POST, I always get a return code of 200 "OK", never "201" (which is what I should receive according to the guide) and the nodes don't get created.

I've updated the rest.settings.yml for both the basic page and my content type, have established permissions for the user, am using basic auth, and have added Content Type application/hal+json and cross-origin details to the header info.

Any idea what's missing? Do I need to add coding in my create entity form to "receive" the posted data? Where do I do this/in which directories should the files go? Is this required for the default Basic Page content type, too?

Thanks for any help...I've spent weeks on this and can't figure out what I'm missing.

Thank you!

Upvotes: 1

Views: 2895

Answers (1)

user3694152
user3694152

Reputation: 9

On Drupal 8 alpha 11 it will work but make sure I am assuming that you have enabled REST , HAL, HTTP basic authentication, Serialization module on your site.

  1. You have enabled POST method for 'entity:node' with basic_auth authentication type and hal_json as format
  2. Give enough permission to a admin so that it can create node via REST , To do so navigate to admin/people/permissions on your drupal installation.

now /entity/node is REST end point to create node I am using REST Client to demonstrate POST request

this is link to image that will make it more clear https://dl.dropboxusercontent.com/u/100492838/POST_Node.png

now make a POST request with Content-Type = hal+json and also set basic_auth header. change URL according to your site.

Upvotes: 0

Related Questions