Chat with us, powered by LiveChat

This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

Say hello to redesigned Cloudways, an empowering Startup Program, enhanced Staging, a new Let’s Encrypt Wildcard SSL certificate feature, and more. GET STARTED

How To Create A Node In Drupal 8 Using RESTful Web Services

Updated on  22nd January

4 Min Read
Reading Time: 4 minutes

RESTful Web Services is an incredibly powerful web tool that enables external resources to interact with applications. With the introduction of Drupal 8, RESTful Web Services was integrated in the Drupal core. This enables Drupal to be extremely flexible and opens up a host of possibilities. In this tutorial, I will introduce you to the web services of Drupal using RESTful Web Services to create a node in Drupal.

create drupal 8 node using restful web services

Using RESTful Web Services, you can create a node in Drupal 8 in 5 simple steps:

  1. Enable Modules
  2. Set Permissions
  3. Get token
  4. Create node
  5. Verify the Rest API call

Enable Modules

Get started by enabling the following 4 core modules in Drupal:

  • HAL
  • HTTP Basic Authentication
  • RESTful Web Services
  • Serialization

I will also be downloading the Rest UI module for Drupal 8. This allows easy settings of permissions and settings for the Restful services through a GUI, instead of going through the rest.settings.yml file.

create drupal 8 node using restful web services

Set Permissions

Next, create a new authenticated user for your site. This way you’ll learn about the kind of permissions that should be set. Alternatively, if you were to be logged in as an admin, you would automatically have all the permissions.

So, go ahead and create a new user. Once done, go to admin/configuration/web services/REST. Here you can enable permissions for every type of resource on your Drupal site. For now, since we’re only concerned with creating content through the RESTful Web Services, go ahead and click edit for the content row and set the following permissions:

create drupal 8 node using restful web services 2

Next, we need to set the proper permissions for authenticated users to be able to create, edit and delete content. Go to admin/people/permissions and set the following permissions:

  • Basic Page: Create new content
  • Basic Page: Delete own content
  • Basic Page: Edit own content

create drupal 8 node using restful web services

Get Token

We are now ready to use REST to create a new node (page content type) in our Drupal site. Note that I will be using the excellent Restlet Client – Rest API Testing extension for chrome to test the API calls in this post. You can use whichever method you prefer.

Before we start creating a node for our site, we will have to get the token for our user in order to pass authentication. Do this by logging out of your site as an admin and logging in as the new authenticated user that we created in the last step. Now copy the URL of your site and paste it in the URL field of the Restlet Client, adding rest/session/token at the end of it. Select the ‘GET’ method from the dropdown and click send to get the token from the body field.

create drupal 8 node using restful web services

Create Node

Now that we have the unique token for our user, we can get started with creating a node for our Drupal site using RESTful Web Services. We will be using the POST method to POST to entity/node, setting the Content-Type to application/hal+json. In the body field, we must declare the required title and type fields in the following way:









   “value”:”My first page”




We will have to add the following headers for this call:

  • Content-Type : application/hal+json
  • X-CSRF-Token : ‘The token that we got from the previous step’

To add authentication, click add authorization and enter the credentials of the user that we created earlier.

create drupal 8 node using restful web services

Here’s what it looks like:

create drupal 8 node using restful web services

Click send and you should receive the 201 created response.

Verify Rest API Call

Now go to your Drupal site and navigate to admin/content. Your API call works perfectly if you see a new node created with the Title that you gave in your API call.

create drupal 8 node using restful web services


That’s it! You’ve successfully created your very own Drupal node by using the RESTful Web Services of Drupal. In this tutorial, we used the POST method. You can use the same procedure to GET, POST, PATCH and DELETE nodes in Drupal as well. Hope you found this guide useful. If you face any issues, leave me a comment and I’ll get back to you.

If you are looking to create nodes in Drupal 7, see our previous blog post on: How To Programmatically Create Nodes In Drupal 7

Share your opinion in the comment section. COMMENT NOW

Hamza Zia

Hamza is a Drupal Community Manager at Cloudways - A Managed Drupal Hosting Platform. He loves to write about Drupal and related topics. During his free time, he can be seen obsessing over Football, Cars, Android and Gaming.

Create interactive Drupal websites easily on the Cloud.

Host your website on optimized Drupal hosting servers.

Get Our Newsletter
Be the first to get the latest updates and tutorials.