Skip to main content

Update a resource with the Node.js SDK

permit.api.resources.update() changes the fields of an existing resource type in the Permit.io environment that your Node.js SDK client is connected to. This reference is for backend developers who change the policy schema from code, for example to add an action.

Prerequisites

Method signature

MethodSignatureStatus
permit.api.resources.updateupdate(resourceKey: string, resourceData: ResourceUpdate): Promise<ResourceRead>Recommended
permit.api.updateResourceupdateResource(resourceId: string, resource: ResourceUpdate): Promise<ResourceRead>Deprecated alias with the same arguments

Parameters

NameTypeRequiredDescription
resourceKeystringYesKey or ID of the resource to update.
resourceDataResourceUpdateYesObject with the fields to change. Pass the object itself, not a JSON string.

The ResourceUpdate object accepts these fields. The resource key can't be changed.

FieldTypeRequiredDescription
namestringNoDisplay name of the resource.
urnstringNoUniform Resource Name (URN) of the resource.
descriptionstringNoWhat the resource represents in your system.
actionsobjectNoActions on the resource. Each key is an action key, and each value is an action definition object.
attributesobjectNoAttributes that each instance of the resource has, for use in attribute-based access control (ABAC) policies.
rolesobjectNoResource roles for relationship-based access control (ReBAC). Each key is a role key, and each value holds the role properties.
relationsobjectNoRelations to other resources. Each key is a relation key, and each value is the related resource.

Example ResourceUpdate object with placeholder values:

{
name: "name",
urn: "urn",
description: "description",
actions: {},
attributes: {},
roles: {},
relations: {}
}

Example

const response = await permit.api.resources.update(resourceKey, resource);

Return value

The method resolves to the updated ResourceRead object, including key, id, name, actions, attributes, and updated_at.

If the resource doesn't exist or the Permit API returns another error status code, permit.api.resources.update() throws a PermitApiError. The deprecated permit.api.updateResource() rethrows the underlying Axios error.