fbpx

Drupal 8.x Delete content node via rest API

Reading time: 2 minutes

Problem

How to Delete Article or any other custom content type node in Drupal 8.x site via rest API by using REST module.

Final output

At the end we will be able to delete an Article node content using rest API in Drupal 8.x

Let’s jump to achieve our goal to delete an article content node or data via rest API in Drupal 8 site.

NOTE: Make sure all the configurations for JSON:API and REST modules has been setup correctly by visiting here

Solution

1. Open up the API testing tool, We are going to test it through rest API using Postman.

Delete Article content type API

* Request:
Method:
DELETE


URL:
{{BASE_URL}}/node/[nid]?_format=hal_json

Headers:
* Authorization: Basic <credentials>Β 
Basic authentication is where the username and password-based authentication takes place.
* X-CSRF-Token: We can get CSRF token in response of Login API.
To see how to get CSRF token in Drupal site
* Content-Type: application/hal+json

* Response
HTTP 204 (No content) response with Empty response body.
The article with {{nid}} is now deleted.

Delete article content type node Response postman
Delete Article content type node via rest API Postman response

Awesome we have done it πŸ₯°

Finally, just go to your admin panel and see inside content list you will see the deleted content is no more there, isn’t it so easy πŸ˜‰

Congratulations now we can Delete Article or any other content type node via rest API by REST module in Drupal 8.x site πŸ™‚

Share your love with us πŸ˜‰

Click on a star to rate it!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

Leave a Reply