Skip to main content

Note

are not stored by Clerk, so they cannot be fetched via the list endpoint (clerkClient.m2m.list()). The list endpoint will only return . Additionally, since JWT verification happens client-side, Clerk cannot track last_used_at for JWT tokens.

Gets a list of M2M tokens for the given machine. By default, the list is returned in descending order by creation date (newest first). This endpoint can be authenticated by either a Machine Secret Key or by a Clerk .

  • When fetching M2M tokens with a Machine Secret Key, only tokens associated with the authenticated machine can be retrieved.
  • When fetching M2M tokens with a Clerk Secret Key, tokens for any machine in the instance can be retrieved.

Returns a PaginatedResourceResponse object with a data property containing an array of M2MToken objects and a totalCount property containing the total number of M2M tokens for the machine.

function list(queryParams: GetM2MTokenListParams): Promise<PaginatedResourceResponse<M2MToken[]>>
  • Name
    expired?
    Type
    boolean
    Description

    Whether to include expired M2M tokens. Defaults to false.

  • Name
    limit?
    Type
    number
    Description

    Maximum number of items returned per request. Must be an integer greater than zero and less than 501. Can be used for paginating the results together with offset. Defaults to 10.

  • Name
    machineSecretKey?
    Type
    string
    Description

    The custom machine secret key for authentication. If not provided, the SDK will use the value from the environment variables.

  • Name
    offset?
    Type
    number
    Description

    Skip the first offset items when paginating. Needs to be an integer greater or equal to zero. To be used in conjunction with limit. Defaults to 0.

  • Name
    revoked?
    Type
    boolean
    Description

    Whether to include revoked M2M tokens. Defaults to false.

  • Name
    subject
    Type
    string
    Description

    The machine ID to query M2M tokens by.

Note

Using clerkClient varies based on the SDK you're using. Refer to the overview for usage details, including guidance on how to access the userId and other properties.

Filter by machine ID

Gets a list of M2M tokens for a machine

const machineId = 'mt_123'

const m2mTokens = await clerkClient.m2m.list({
  subject: machineId,
})

Filter by machine ID, including revoked and expired tokens

Gets a list of M2M tokens for a machine, including revoked and expired ones

const machineId = 'mt_123'

const m2mTokens = await clerkClient.m2m.list({
  subject: machineId,
  revoked: true,
  expired: true,
})

Filer by machine ID, including revoked and expired tokens, with pagination

Gets a list of M2M tokens for a machine with pagination

const machineId = 'mt_123'

const m2mTokens = await clerkClient.m2m.list({
  subject: machineId,
  limit: 20,
  offset: 0,
})

Backend API (BAPI) endpoint

This method in the SDK is a wrapper around the BAPI endpoint GET/m2m_tokens. See the BAPI reference for more information.

Feedback

What did you think of this content?

Last updated on