# 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](https://www.datocms.com/docs/content-management-api/resources/access-token/regenerate-token.md) 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.

> [!WARNING] ⚠️ 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

**`name`**

- Required
- Type: string
- Example: `"Read-only API token"`

Name of API token

**`can_access_cda`**

- Required
- Type: boolean

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

**`can_access_cda_preview`**

- Required
- Type: boolean

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.

**`can_access_cma`**

- Required
- Type: boolean

Whether this API token can access the Content Management API

**`role`**

- Optional
- Type: [ResourceLinkage\<"role"\>](https://www-draft.datocms.com/docs/content-management-api/resources/role.md)

Role

## Returns

Returns a resource object of type [access\_token](https://www.datocms.com/docs/content-management-api/resources/access-token.md)

## Examples

###### Example Basic example

Code

```javascript
import { buildClient } from "@datocms/cma-client-node";

async function run() {
  const client = buildClient({ apiToken: process.env.DATOCMS_API_TOKEN });

  const accessTokenId = "312";

  const accessToken = await client.accessTokens.update(accessTokenId, {
    id: "312",
    name: "Read-only API token",
    can_access_cda: true,
    can_access_cda_preview: true,
    can_access_cma: true,
  });

  // Check the 'Returned output' tab for the result ☝️
  console.log(accessToken);
}

run();
```

Returned output

```javascript
{
  id: "312",
  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",
  role: { type: "role", id: "34" },
}
```

## Related content in "Content Management API"

- [Content Management API Overview](https://www.datocms.com/docs/content-management-api.md)
- [Using the JavaScript CMA client](https://www.datocms.com/docs/content-management-api/using-the-nodejs-clients.md)
- [API versioning](https://www.datocms.com/docs/content-management-api/api-versioning.md)
- [Authentication](https://www.datocms.com/docs/content-management-api/authentication.md)
- [Environments](https://www.datocms.com/docs/content-management-api/setting-the-environment.md)
- [Error codes & handling failures (CMA)](https://www.datocms.com/docs/content-management-api/errors.md)
- [Pagination](https://www.datocms.com/docs/content-management-api/pagination.md)
- [Asynchronous jobs](https://www.datocms.com/docs/content-management-api/async-jobs.md)
- [CMA Technical Limits & Rate Limits](https://www.datocms.com/docs/content-management-api/technical-limits.md)
- [Record](https://www.datocms.com/docs/content-management-api/resources/item.md)
- [Scheduled publication](https://www.datocms.com/docs/content-management-api/resources/scheduled-publication.md)
- [Scheduled unpublishing](https://www.datocms.com/docs/content-management-api/resources/scheduled-unpublishing.md)
- [Upload](https://www.datocms.com/docs/content-management-api/resources/upload.md)
- [Site](https://www.datocms.com/docs/content-management-api/resources/site.md)
- [Model/Block model](https://www.datocms.com/docs/content-management-api/resources/item-type.md)
- [Field](https://www.datocms.com/docs/content-management-api/resources/field.md)
- [Fieldset](https://www.datocms.com/docs/content-management-api/resources/fieldset.md)
- [Record version](https://www.datocms.com/docs/content-management-api/resources/item-version.md)
- [Upload permission](https://www.datocms.com/docs/content-management-api/resources/upload-request.md)
- [Upload track](https://www.datocms.com/docs/content-management-api/resources/upload-track.md)
- [Manual tags](https://www.datocms.com/docs/content-management-api/resources/upload-tag.md)
- [Smart tags](https://www.datocms.com/docs/content-management-api/resources/upload-smart-tag.md)
- [Upload Collection](https://www.datocms.com/docs/content-management-api/resources/upload-collection.md)
- [Search Index](https://www.datocms.com/docs/content-management-api/resources/search-index.md)
- [Search result](https://www.datocms.com/docs/content-management-api/resources/search-result.md)
- [Search indexing activity](https://www.datocms.com/docs/content-management-api/resources/search-index-event.md)
- [Environment](https://www.datocms.com/docs/content-management-api/resources/environment.md)
- [Maintenance mode](https://www.datocms.com/docs/content-management-api/resources/maintenance-mode.md)
- [Menu Item](https://www.datocms.com/docs/content-management-api/resources/menu-item.md)
- [Schema Menu Item](https://www.datocms.com/docs/content-management-api/resources/schema-menu-item.md)
- [Uploads filter](https://www.datocms.com/docs/content-management-api/resources/upload-filter.md)
- [Model filter](https://www.datocms.com/docs/content-management-api/resources/item-type-filter.md)
- [Plugin](https://www.datocms.com/docs/content-management-api/resources/plugin.md)
- [Workflow](https://www.datocms.com/docs/content-management-api/resources/workflow.md)
- [Asynchronous job](https://www.datocms.com/docs/content-management-api/resources/job.md)
- [Job result](https://www.datocms.com/docs/content-management-api/resources/job-result.md)
- [Account](https://www.datocms.com/docs/content-management-api/resources/account.md)
- [Organization](https://www.datocms.com/docs/content-management-api/resources/organization.md)
- [Invitation](https://www.datocms.com/docs/content-management-api/resources/site-invitation.md)
- [Collaborator](https://www.datocms.com/docs/content-management-api/resources/user.md)
- [Role](https://www.datocms.com/docs/content-management-api/resources/role.md)
- [API token](https://www.datocms.com/docs/content-management-api/resources/access-token.md)
- [Create a new API token](https://www.datocms.com/docs/content-management-api/resources/access-token/create.md)
- [Update an API token](https://www.datocms.com/docs/content-management-api/resources/access-token/update.md)
- [List all API tokens](https://www.datocms.com/docs/content-management-api/resources/access-token/instances.md)
- [Retrieve an API token](https://www.datocms.com/docs/content-management-api/resources/access-token/self.md)
- [Rotate API token](https://www.datocms.com/docs/content-management-api/resources/access-token/regenerate_token.md)
- [Delete an API token](https://www.datocms.com/docs/content-management-api/resources/access-token/destroy.md)
- [Webhook](https://www.datocms.com/docs/content-management-api/resources/webhook.md)
- [Webhook call](https://www.datocms.com/docs/content-management-api/resources/webhook-call.md)
- [Build trigger](https://www.datocms.com/docs/content-management-api/resources/build-trigger.md)
- [Deploy activity](https://www.datocms.com/docs/content-management-api/resources/build-event.md)
- [Subscription limit](https://www.datocms.com/docs/content-management-api/resources/subscription-limit.md)
- [Subscription feature](https://www.datocms.com/docs/content-management-api/resources/subscription-feature.md)
- [SSO Settings](https://www.datocms.com/docs/content-management-api/resources/sso-settings.md)
- [SSO User](https://www.datocms.com/docs/content-management-api/resources/sso-user.md)
- [SSO Group](https://www.datocms.com/docs/content-management-api/resources/sso-group.md)
- [White-label settings](https://www.datocms.com/docs/content-management-api/resources/white-label-settings.md)
- [Audit log event](https://www.datocms.com/docs/content-management-api/resources/audit-log-event.md)