Show examples in:
Javascript HTTP
Endpoint info
Available examples
Content Management API > API token

Update an API token

Updates an API token's name, role, or API surface flags. The token's secret value is not affected — to rotate it, use the Rotate API token endpoint.

If you omit relationships from the payload, the token's existing role is preserved. Send relationships.role only when you want to reassign the token to a different role.

Changes to the role or surface flags take effect immediately. A request that was permitted under the previous configuration may be rejected on the very next call once the new permissions have been written.

⚠️ Hardcoded tokens cannot be edited

The project's built-in factory tokens (those whose attributes.hardcoded_type is non-null) reject this endpoint with NON_EDITABLE_ACCESS_TOKEN. They can still be deleted or rotated.

Body parameters

type string Required

Must be exactly "access_token".

attributes.name string Required

Name of API token

Example: "Read-only API token"
attributes.can_access_cda boolean Required

Whether this API token can call the Content Delivery API (graphql.datocms.com) to fetch published content.

attributes.can_access_cda_preview boolean Required

Whether this API token can call the Content Delivery API with the X-Include-Drafts: true header to fetch draft (current, unpublished) content. There is no separate endpoint — the CDA is a single GraphQL endpoint and this flag governs whether requesting drafts is allowed.

attributes.can_access_cma boolean Required

Whether this API token can access the Content Management API

relationships.role.data Optional

Role

Returns

Returns a resource object of type access_token.

Examples

PUT https://site-api.datocms.com/access_tokens/:access_token_id HTTP/1.1
Authorization: Bearer YOUR-API-TOKEN
Accept: application/json
X-Api-Version: 3
Content-Type: application/vnd.api+json
{
"data": {
"type": "access_token",
"id": "312",
"attributes": {
"name": "Read-only API token",
"can_access_cda": true,
"can_access_cda_preview": true,
"can_access_cma": true
}
}
}
Terminal window
curl -g 'https://site-api.datocms.com/access_tokens/:access_token_id' \
-X PUT \
-H "Authorization: Bearer YOUR-API-TOKEN" \
-H "Accept: application/json" \
-H "X-Api-Version: 3" \
-H "Content-Type: application/vnd.api+json" \
--data-binary '{"data":{"type":"access_token","id":"312","attributes":{"name":"Read-only API token","can_access_cda":true,"can_access_cda_preview":true,"can_access_cma":true}}}'
await fetch("https://site-api.datocms.com/access_tokens/:access_token_id", {
method: "PUT",
headers: {
Authorization: "Bearer YOUR-API-TOKEN",
Accept: "application/json",
"X-Api-Version": "3",
"Content-Type": "application/vnd.api+json",
},
body: JSON.stringify({
data: {
type: "access_token",
id: "312",
attributes: {
name: "Read-only API token",
can_access_cda: true,
can_access_cda_preview: true,
can_access_cma: true,
},
},
}),
});
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: cache-control: max-age=0, private, must-revalidate
X-RateLimit-Limit: 30
X-RateLimit-Remaining: 28
{
"data": {
"type": "access_token",
"id": "312",
"attributes": {
"name": "Read-only API token",
"hardcoded_type": "",
"can_access_cda": true,
"can_access_cda_preview": true,
"can_access_cma": true,
"last_cma_access": "never",
"last_cda_access": "never"
},
"relationships": {
"role": {
"data": {
"type": "role",
"id": "34"
}
}
}
}
}