updateResource

Update a resource.


const resource = await drupal.updateResource<T = JsonApiResource>(
type,
uuid,
body,
options?: {
params,
withAuth,
deserialize,
}
): Promise<T>
  • type: string
    • Required
    • The resource type. Example: node--article, taxonomy_term--tags, or block_content--basic.
  • uuid: string
    • Required
    • The resource id. Example a50ffee7-ba94-46c9-9705-f9f8f440db94.
  • body: JsonApiUpdateResourceBody
    • Required
    • The body payload with data.
  • options
    • Optional
    • params: JsonApiParams: JSON:API params such as filter, fields, include or sort.
    • withAuth: boolean | DrupalClientAuth:
      • Set the authentication method to use. See the authentication docs.
      • Set to true to use the authentication method configured on the client.
    • deserialize: boolean: Set to false to return the raw JSON:API response.

Examples

  • Update a node--page resource.
const page = await drupal.updateResource(
"node--page",
"a50ffee7-ba94-46c9-9705-f9f8f440db94",
{
data: {
attributes: {
title: "Updated Title",
},
},
}
)

TypeScript

  • Using DrupalNode for a node entity type.
import { DrupalNode } from "next-drupal"
const page = await drupal.updateResource<DrupalNode>(
"node--page",
"a50ffee7-ba94-46c9-9705-f9f8f440db94",
{
data: {
attributes: {
title: "Updated Title",
},
},
}
)

See the TypeScript docs for more built-in types.