Last updated November 12, 2015. Created on September 26, 2013.
Edited by bigjim, subhojit777, Jaesin, askibinski. Log in to edit this page.


Currently *, the only core format which can handle POST requests is application/hal+json. Enable HAL module to support this media type.

* Related issue to support application/json for POST

In the following examples we use HTTP Basic Authentication to authenticate the request so make sure to enable the module.


As most of the content in Drupal has relations make sure the relations are properly added to the payload.

As we must use HAL the relations are currently through the _links entry. Issues in need to fix this are in both[]=8.x&compon... and[]=8.x&compon...

For instance if you want to POST a new comment you need a _link entry to the user and to the entity the comment is for. Best way to get this is to first GET an example and study its _links.

Never POST a uuid as you create a new entity.


Follow the steps in the GET configuration instructions. To enable POSTing to a resource, you must add it to the nested array for the resource. For example, the following config enables both GET and POST on nodes.

# Example configuration for enabling REST resources.
  # Enable the node resource.
        - json
        - hal_json
        - basic_auth
        - hal_json
        - basic_auth

Setting permissions

Permissions are configured using the same steps as for GET requests. Typically, a limited number of roles will be given access to POST content entities.

Testing with a POST request

To follow these tests, grant access to the role which you are testing with. To ensure that authentication is working, you should not grant access to the anonymous user until you have verified that it is working.

cURL (command line)

curl --include \
  --request POST \
  --user klausi:secret \
  --header 'Content-type: application/hal+json' \
  --header 'X-CSRF-Token: <obtained from /rest/session/token>' \
  http://drupal-8.localhost/entity/node?_format=hal_json \
  --data-binary '{"_links":{"type":{"href":"http://drupal-8.localhost/rest/type/node/article"}},"title":[{"value":"test title"}],"type":[{"target_id":"article"}]}'


// Prepare entity data.
$serialized_entity = json_encode([
  'title' => [['value' => 'Example node title']],
  'type' => [['target_id' => 'article']],
  '_links' => ['type' => [
      'href' => ''

// Create the Node.
$response = \Drupal::httpClient()
  ->post('', [
    // Username and password for HTTP Basic Authentication.
    'auth' => ['admin', 'drupal'],
    'body' => $serialized_entity,
    'headers' => [
      'Accept' => 'application/hal+json',
      'Content-Type' => 'application/hal+json',
      'X-CSRF-Token' => <obtained from /rest/session/token>

// Check for the correct status code.
if ($response->getStatusCode() == 201) {
  print 'Node creation successful!';

Dev HTTP client

Post example81.49 KB
Drupal_8_POST_DHC.png194.44 KB

Looking for support? Visit the forums, or join #drupal-support in IRC.


designdit’s picture


Thanks for the guides - I've had success with the "Get on content entities" and "Get on Views-generates lists" guides, but can't get the post to work. I've tried to POST 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 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" and the nodes don't get created.

I've updated the rest.settings.yml and have established permissions for the user. 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.


vivekvpandya’s picture

christianmgrupp’s picture


I am just jumping into Drupal 8 and familiarizing myself with HAL. I am able to successfully able to create a node of type "basic page" with the following CURL script:
curl --include --request POST --user test-user:XXXXXXX --header 'Content-type: application/hal+json' http://d8beta.dd:8083/entity/node --data-binary '{"_links":{"type":{"href":"http://d8beta.dd:8083/rest/type/node/page"}}, "title":[{"value":"My first page"}]}'

I have a custom content type with a machine name of "test_content_type"

When I try to submit the following it still adds it as a basic page:
curl --include --request POST --user test-user:XXXXXX --header 'Content-type: application/hal+json' http://d8beta.dd:8083/entity/node --data-binary '{"_links":{"type":{"href":"http://d8beta.dd:8083/rest/type/node/page"}}, "title":[{"value":"My first page"}],"type":[{"target_id":"test_content_type"}]}'

When I submit the following it gives me an error saying that: {"error":"Type http:\/\/d8beta.dd:8083\/rest\/type\/node\/test_content_type does not correspond to an entity on this site."} :
curl --include --request POST --user test-user:XXXXXX --header 'Content-type: application/hal+json' http://d8beta.dd:8083/entity/node --data-binary '{"_links":{"type":{"href":"http://d8beta.dd:8083/rest/type/node/test_content_type"}}, "title":[{"value":"My first page"}],"type":[{"target_id":"test_content_type"}]}'

I am running the latest version of the Drupal 8 beta (8.0.0-beta12).

Thanks in advance for the help!

likewhoa’s picture

@christianmgrupp just remove ""type":[{"target_id":"test_content_type"}]" as you are already referencing the content type.

Bending technology to fit business

christianmgrupp’s picture

{Edited out earlier reply of density}

Yep, that's it.

Thank you for the help.

gdevashi’s picture

Please give me example how to POST two or more articles at once?
Something like this:
"title":[{"value":"Title 1"} ],
"title":[{"value":"Title 2"} ],
Result: Status Code: 400 Bad Request "Syntax error"

It is even possible for a single request to add more than one article?

sgroves’s picture

Very useful resource.

Can the POST method support sending full html markup? Or only basic?

rabithk’s picture

Hi ,
Any one share the example code for Drupal 8 rc 4 , REST services for creating a new user . I think the above description is not updated as per D8 core update .
I have an external website posting user registration to my Drupal 8 website .

ziobudda’s picture

Rabith, have you resolved your question ? If yes, how ?



Freelancer Senior Drupal Developer --

dafnie’s picture


Thanks for a really good documentation of restful services in Drupal.
I have searched and searched on, but could not find any hint that can help me on my special problem.

I have some XML data that is sent to drupal via http post. These XML data need to create a content type called property. However, the data can not be directly used in a node, as they have no drupal data structure.
I think that I instead will post to a folder and then use feeds to import and then manipulate the data. But how is it possible to generate a file from a http post? Or do I have to think in an other direction?