Using PATCH to update data with JSON:API
Now that we know how to create some data in Drupal, let’s learn how to update existing data.
How to do it…
Our request will look similar to the POST
request from the previous sections but with a few changes.
First, to update an entity in Drupal, you need to pass the entity UUID in the request payload for it to work. This is different than the numeric entity ID. You can get the UUID from fetching data from JSON:API, as we saw in the Fetching data from Drupal using JSON:API section. For the node that we created in our POST
request, the UUID value is 1ddf244d-e8e6-40f5-be48-23bc8fa0fa3e
.
Let’s go ahead and change the title and body of the article node we created previously. This time, we must pass the UUID in the URL as well as the request body:
curl \ --user chapter12:chapter12 \ --header 'Accept: application/vnd.api+json' \ &...