# Create a token

Creates a query token. The scope and permissions of the token are specified through the request TokenParameters object that includes a required label and expiration date and time (such as `"expiration": "2025-01-15T15:30:00Z"`), an optional description, along with other restrictions, such as:
- Publish State  - the publish state the token is restricted to (either `Preview, Published, or both`), for example, `"publishState": ["Published"]`. This property can be empty, but cannot be `Unknown`.
- Branches - the name of the branches that token access is restricted to, for example, `"branches": "main, dev, release/*"]`. For a prefix match, use `/*`. This property can be empty.
- Source IPs - the source IP addresses that token access is restricted to, for example, `"sourceIPs": ["192.168.20.101"]`. This property can be empty.
- Origins - the origins that the token access is restricted to. This is a CORS feature and takes effect only when a request includes the `Origin` header. This property can be empty.
- Introspection - whether GraphQL introspection is allowed when using this token. It is recommended that introspection only be enabled for development environments.

 We recommend an expiration date of one
year at the most. You cannot change the expiration date after you create a token
without generating a  new token.

Endpoint: POST /api/token/v2
Version: v2.0
Security: Bearer

## Security:

  - `Bearer` (unknown)
    http Bearer JWT

## Request body:

  - `application/json` (unknown)
    The token creation parameters details.

## Request fields (application/json):

  - `label` (string)
    The label of the token.

  - `description` (string)
    The description of the token.

  - `managePersistedQueries` (boolean)
    Whether the token can manage persisted queries.

  - `expiration` (string)
    The expiration date and time of the token.

  - `restrictions` (object)
    Represents the restrictions associated with a token.
    Example: {"publishState":["Published"],"branches":["main"],"origins":["https://myapp.com"],"sourceIPs":["127.0.0.1"],"introspection":true}

  - `restrictions.publishState` (array)
    Gets or sets the publish states associated with the token.

  - `restrictions.branches` (array)
    Gets or sets the branches associated with the token. This can be an exact match with the branch ID or a prefix match.

  - `restrictions.sourceIPs` (array)
    Gets or sets the source IP addresses associated with the token.

  - `restrictions.origins` (array)
    Gets or sets the origins associated with the token.

  - `restrictions.introspection` (boolean)
    Gets or sets a value indicating whether introspection is allowed.

## Response 201:

  - `201` (unknown)
    The token was successfully created. Token details are returned with the token value.

## Response 201 fields (application/json):

  - `id` (string)
    The unique identifier of the token.

  - `label` (string)
    The label of the token.

  - `description` (string)
    The description of the token.

  - `managePersistedQueries` (boolean)
    Whether the token can manage persisted queries.

  - `token` (string)
    The token string.

  - `expiration` (string)
    The expiration date and time of the token.

  - `restrictions` (object)
    Represents the restrictions associated with a token.
    Example: {"publishState":["Published"],"branches":["main"],"origins":["https://myapp.com"],"sourceIPs":["127.0.0.1"],"introspection":true}

  - `restrictions.publishState` (array)
    Gets or sets the publish states associated with the token.

  - `restrictions.branches` (array)
    Gets or sets the branches associated with the token. This can be an exact match with the branch ID or a prefix match.

  - `restrictions.sourceIPs` (array)
    Gets or sets the source IP addresses associated with the token.

  - `restrictions.origins` (array)
    Gets or sets the origins associated with the token.

  - `restrictions.introspection` (boolean)
    Gets or sets a value indicating whether introspection is allowed.

  - `system` (object)
    Contains system metadata and tracking information for a token. This includes creation details that are automatically populated by the system.

  - `system.createdAt` (string)
    The date and time when the token was created.

  - `system.createdBy` (object)

  - `system.createdBy.type` (string)

  - `system.createdBy.relatedType` (string)

  - `system.createdBy.id` (string)

  - `system.createdBy.uri` (string)

## Response 400:

  - `400` (unknown)
    Invalid input in the request body

## Response 400 fields (application/json):

  - `type` (string)

  - `title` (string)

  - `status` (integer)

  - `detail` (string)

  - `instance` (string)

  - `errors` (object)

## Response 401:

  - `401` (unknown)
    Invalid bearer token

## Response 401 fields (application/json):

  - `type` (string)

  - `title` (string)

  - `status` (integer)

  - `detail` (string)

  - `instance` (string)

## Response 403:

  - `403` (unknown)
    Request does not contain required scopes

## Response 403 fields (application/json):

  - `type` (string)

  - `title` (string)

  - `status` (integer)

  - `detail` (string)

  - `instance` (string)

