Using DELETE to remove data with JSON:API
Finally, we have come to the final action of the CRUD acronym: the delete
method. This method removes requested data in Drupal, provided you have the UUID.
How to do it…
Like PATCH
, issuing DELETE
requires the appropriate permission in Drupal. In this case, the role assigned to our API user needs to be allowed to delete article nodes. Head back to the permissions section of the Drupal admin area and grant Article: Delete any content to the role.
We need to assign delete any
instead of delete own
since we assigned the node ownership to another user.
All the DELETE
request needs is the UUID of the entity we wish to remove. Using the node we created, the UUID of it is 1ddf244d-e8e6-40f5-be48-23bc8fa0fa3e
. The DELETE
request looks like this:
curl \ --user chapter12:chapter12 \ --header 'Accept: application/vnd.api+json' \ ...