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
- A
permitclient created with an API key for the environment. See Create a Permit client. - An existing resource. See Create a resource with the Node.js SDK.
Method signature
| Method | Signature | Status |
|---|---|---|
permit.api.resources.update | update(resourceKey: string, resourceData: ResourceUpdate): Promise<ResourceRead> | Recommended |
permit.api.updateResource | updateResource(resourceId: string, resource: ResourceUpdate): Promise<ResourceRead> | Deprecated alias with the same arguments |
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
resourceKey | string | Yes | Key or ID of the resource to update. |
resourceData | ResourceUpdate | Yes | Object 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.
| Field | Type | Required | Description |
|---|---|---|---|
name | string | No | Display name of the resource. |
urn | string | No | Uniform Resource Name (URN) of the resource. |
description | string | No | What the resource represents in your system. |
actions | object | No | Actions on the resource. Each key is an action key, and each value is an action definition object. |
attributes | object | No | Attributes that each instance of the resource has, for use in attribute-based access control (ABAC) policies. |
roles | object | No | Resource roles for relationship-based access control (ReBAC). Each key is a role key, and each value holds the role properties. |
relations | object | No | Relations 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.