Skip to main content

Note

Looking for the and you use to connect your own app to Clerk? Those are different from the API keys described here. You can copy them from the API keys page in the Clerk Dashboard, or learn more in the Clerk environment variables reference.

Updates the given API key.

Returns the updated APIKey object.

function update(params: UpdateAPIKeyParams): Promise<APIKey>
  • Name
    apiKeyId
    Type
    string
    Description

    The ID of the API key to update.

  • Name
    claims?
    Type
    Record<string, any> | null
    Description

    Custom claims to store additional information about the API key.

  • Name
    description?
    Type
    string | null
    Description

    The description of the API key.

  • Name
    scopes?
    Type
    string[]
    Description

    Scopes to limit the API key's access to specific resources.

  • Name
    secondsUntilExpiration?
    Type
    number | null
    Description

    The number of seconds until the API key expires. Defaults to null (never expires).

  • Name
    subject
    Type
    string
    Description

    The user or Organization ID to associate the API key with.

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.

const apiKeyId = 'apikey_123'
const userId = 'user_123'

const response = await clerkClient.apiKeys.update({
  apiKeyId: apiKeyId,
  subject: userId,
  description: 'API key for accessing my application',
  scopes: ['read:users', 'write:users'],
  secondsUntilExpiration: 86400, // expires in 24 hours
})

Backend API (BAPI) endpoint

This method in the SDK is a wrapper around the BAPI endpoint PATCH/api_keys/{apiKeyID}. See the BAPI reference for more information.

Feedback

What did you think of this content?

Last updated on