Skip to main content
Docs

update()

Warning

API keys is currently in beta. The API may change before general availability.

Updates an API key by its ID. Returns an APIKeyResourceJavaScript Icon object.

function update(params: UpdateAPIKeyParams): Promise<APIKeyResource>
  • Name
    apiKeyID
    Type
    string
    Description

    The ID of the API key to update.

  • Name
    subject
    Type
    string
    Description

    The user ID (user_xxx) or organization ID (org_xxx) to associate the API key with.

  • Name
    description?
    Type
    string | null
    Description

    A longer description of what the API key is used for.

  • Name
    scopes?
    Type
    string[]
    Description

    An array of scope strings that define what the API key can access.

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

    Additional custom claims to store additional information about the API key.

  • Name
    secondsUntilExpiration?
    Type
    number | null
    Description

    Number of seconds until the API key expires. Defaults to null (API key does not expire).

Note

Using clerkClient varies based on your framework. Refer to the JS Backend SDK 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