Choose your language:
    Create a new API token
    Parameters
    name  string  Optional

    Name of API token

    canAccessCda  boolean  Optional

    Whether this API token can access the Content Delivery API published content endpoint

    canAccessCdaPreview  boolean  Optional

    Whether this API token can access the Content Delivery API draft content endpoint

    canAccessCma  boolean  Optional

    Whether this API token can access the Content Management API

    role  role.id, null  Optional

    Role

    Returns
    Returns a access_token object.

    Examples

    Example code:
    const SiteClient = require('datocms-client').SiteClient;
    const client = new SiteClient('YOUR-API-TOKEN');
    client.accessToken.create({
    name: 'Read-only API token',
    canAccessCda: true,
    canAccessCdaPreview: true,
    canAccessCma: true,
    role: '34'
    })
    .then((accessToken) => {
    console.log(accessToken);
    })
    .catch((error) => {
    console.error(error);
    });
    Returned output:
    > node example.js
    {
    "id": "312",
    "name": "Read-only API token",
    "token": "XXXXXXXXXXXXXXX",
    "canAccessCda": true,
    "canAccessCdaPreview": true,
    "canAccessCma": true,
    "hardcodedType": "",
    "role": "34"
    }