Tokens API — Mutations
Create, revoke, and manage scopes on API tokens. Also supports machine-to-machine (M2M) authentication via client credentials.
createToken
Create a new API token.
Authentication: Requires logged-in user (JWT).
A description for the token.
Optional expiration date (RFC 3339 format).
Returns NewToken. The unredactedToken value is only returned once at creation.
type Mutation {
createToken(input: CreateTokenInput!): NewToken!
}mutation CreateToken($input: CreateTokenInput!) {
createToken(input: $input) {
unredactedToken
token {
id
description
createdAt
expiresAt
}
}
}{
"input": {
"description": "Production reporting token",
"expiresAt": "2025-07-01T00:00:00Z"
}
}revokeToken
Revoke an existing API token. Only the token creator or staff can revoke.
Authentication: Requires logged-in user (JWT). Must be the token owner or staff.
The ID of the token to revoke.
type Mutation {
revokeToken(tokenId: ID!): Boolean!
}mutation RevokeToken($tokenId: ID!) {
revokeToken(tokenId: $tokenId)
}{
"tokenId": "token-001"
}addTokenScope
Add an authorization scope to an existing token.
Authentication: Requires staff role.
The token to add the scope to.
The type of scope.
The scope key (e.g., company ID).
type Mutation {
addTokenScope(input: AddTokenScopeInput!): Token!
}mutation AddScope($input: AddTokenScopeInput!) {
addTokenScope(input: $input) {
id
scopes {
id
scopeType
scopeKey
}
}
}{
"input": {
"tokenId": "token-001",
"scopeType": "COMPANY",
"scopeKey": "4821"
}
}removeTokenScope
Remove a scope from an existing token.
Authentication: Requires staff role.
The token ID.
The scope ID to remove.
type Mutation {
removeTokenScope(tokenId: ID!, scopeId: ID!): Token!
}mutation RemoveScope($tokenId: ID!, $scopeId: ID!) {
removeTokenScope(tokenId: $tokenId, scopeId: $scopeId) {
id
scopes {
id
scopeType
scopeKey
}
}
}createClientCredential
Create a new client credential (client ID + secret) bound to one or more companies. Used for machine-to-machine (M2M) authentication — the credential can later be exchanged for short-lived API tokens via generateToken without requiring a user JWT.
Authentication: Requires logged-in user (JWT). Non-staff users must be an active learner in every specified company.
The company IDs to bind this credential to.
When true, revokes all existing active credentials that overlap with any of the specified company IDs before creating the new one. Defaults to false.
Returns NewClientCredential. The clientSecret is only returned once — store it securely.
type Mutation {
createClientCredential(input: CreateClientCredentialInput!): NewClientCredential!
}mutation CreateClientCredential($input: CreateClientCredentialInput!) {
createClientCredential(input: $input) {
clientId
clientSecret
credential {
id
companyIds
createdAt
}
}
}{
"input": {
"companyIds": ["4821"],
"revokeExisting": true
}
}revokeClientCredential
Revoke a client credential by its ID. Any tokens previously generated with this credential will continue to work until they expire.
Authentication: Requires logged-in user (JWT).
The ID of the credential to revoke.
type Mutation {
revokeClientCredential(credentialId: ID!): Boolean!
}mutation RevokeClientCredential($credentialId: ID!) {
revokeClientCredential(credentialId: $credentialId)
}{
"credentialId": "credential-001"
}generateToken
Exchange a client ID and secret for a short-lived API token with a COMPANY scope automatically attached. This is the core machine-to-machine (M2M) flow — no user JWT required.
When a credential is bound to multiple companies, companyId is required to specify which company the token should be scoped to.
Authentication: No JWT required. The client credentials serve as the authentication mechanism.
The client ID of the credential.
The client secret of the credential.
The company to generate a COMPANY-scoped token for. Required when the credential is bound to multiple companies; omit to default to the credential’s only company.
Returns NewToken with unredactedToken, expiresIn, and primaryScope populated.
type Mutation {
generateToken(input: GenerateTokenInput!): NewToken!
}mutation GenerateToken($input: GenerateTokenInput!) {
generateToken(input: $input) {
unredactedToken
expiresIn
primaryScope {
scopeType
scopeKey
}
}
}{
"input": {
"clientId": "my-client-id",
"clientSecret": "my-client-secret",
"companyId": "4821"
}
}