Updating Resources (PATCH)
How to update JSON:API resources using NextDrupal client.
⚠️
The updateResource
helper is available in next-drupal ^1.4.0
.
If you're working with JSON:API, be mindful to select the option:
Accept all JSON:API create, read, update, and delete operations.
on the following path: /admin/config/services/jsonapi
on Drupal.
The NextDrupal
client ships with a updateResource
method for updating JSON:API resources.
updateResource
Update Resource
const article = await drupal.updateResource( "node--article", "a937dd34-5407-4fff-8594-fccaaa5bb72a", // <-- Article ID { data: { attributes: { title: "Title of Article", }, }, })
Update Resource with Relationships
const article = await drupal.updateResource( "node--article", "a937dd34-5407-4fff-8594-fccaaa5bb72a", { data: { attributes: { title: "Title of Article", }, relationships: { field_media_image: { data: { type: "media--image", id: media.id, }, }, }, }, })
See the API reference for updateResource.
Authentication
To make authenticated requests when updating resources, use the withAuth
option.
See the authentication docs for the supported authentication methods.
const article = await drupal.updateResource( "node--article", "a937dd34-5407-4fff-8594-fccaaa5bb72a", { data: { attributes: { title: "Title of Article", }, }, }, { withAuth: // <-- Your auth method here. })