createToken()
Creates a new M2M token. Must be authenticated via a Machine Secret Key.
function createToken(params?: CreateM2MTokenParams): Promise<M2MToken>- Name
 machineSecretKey?- Type
 string- Description
 Custom machine secret key for authentication. If not provided, the SDK will use the value from the environment variable.
- Name
 secondsUntilExpiration?- Type
 number | null- Description
 Number of seconds until the token expires. Defaults to
null(token does not expire).
- Name
 claims?- Type
 Record<string, unknown> | null- Description
 Additional custom claims to include in the token payload.
const m2mToken = await clerkClient.m2m.createToken()
console.log(m2mToken)While it is strongly recommended to use environment variables for security, if you need to pass in the machine secret key directly rather than using an environment variable, you can do so by passing it as an argument to the createToken() method, as shown in the following example:
const m2mToken = await clerkClient.m2m.createToken({
  machineSecretKey: 'ak_xxx',
})
console.log(m2mToken)Backend API (BAPI) endpoint
This method in the SDK is a wrapper around the BAPI endpoint POST/m2m_tokens. See the BAPI reference for more information.
Feedback
Last updated on