> ## Documentation Index
> Fetch the complete documentation index at: https://docs.enkryptify.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Rotate an API token

> Generates a new token value with the same name, permission, scope and expiration. The previous value is revoked immediately. The new raw `ek_live_` value is returned **once**.



## OpenAPI

````yaml /api-reference/openapi.json post /v1/workspace/{ws}/tokens/{tokenId}/rotate
openapi: 3.0.3
info:
  title: Enkryptify API
  version: 1.0.0
  description: >-
    REST API for Enkryptify. Manage secrets, projects, teams and workspaces.
    Authenticate with an `ek_live_` API token via the `Authorization: Bearer`
    header. See https://docs.enkryptify.com/api-reference/introduction.
servers:
  - url: http://localhost:8080
    description: Production
security: []
tags:
  - name: auth
    description: Token exchange and authentication for API access.
  - name: workspace
    description: Workspaces group your projects, teams and members.
  - name: project
    description: Projects organize secrets per application or service.
  - name: team
    description: Teams scope which members can access which projects.
  - name: secret
    description: Read, create, update and delete secret values.
  - name: secret-share
    description: Create and consume time-bound encrypted secret shares.
  - name: tokens
    description: Manage API tokens for programmatic access.
  - name: sync
    description: Manage integrations that sync secrets to external systems.
  - name: me
    description: Inspect the authenticated user, sessions and preferences.
  - name: oidc
    description: Workspace-scoped OpenID Connect identity federation.
paths:
  /v1/workspace/{ws}/tokens/{tokenId}/rotate:
    post:
      tags:
        - tokens
      summary: Rotate an API token
      description: >-
        Generates a new token value with the same name, permission, scope and
        expiration. The previous value is revoked immediately. The new raw
        `ek_live_` value is returned **once**.
      operationId: rotateApiToken
      parameters:
        - schema:
            anyOf:
              - type: string
                minLength: 2
                maxLength: 48
                pattern: ^[a-z0-9-]+$
              - type: string
                format: uuid
                pattern: >-
                  ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$
          in: path
          name: ws
          required: true
        - schema:
            type: string
            format: uuid
            pattern: >-
              ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$
          in: path
          name: tokenId
          required: true
      responses:
        '201':
          description: Default Response
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    format: uuid
                    pattern: >-
                      ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$
                  token:
                    type: string
                  name:
                    type: string
                  prefix:
                    type: string
                  permission:
                    type: string
                    enum:
                      - read
                      - read-write
                  scope:
                    type: object
                    properties:
                      all:
                        type: boolean
                      teams:
                        type: array
                        items:
                          type: string
                          format: uuid
                          pattern: >-
                            ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$
                      projects:
                        type: array
                        items:
                          type: string
                          format: uuid
                          pattern: >-
                            ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$
                      environments:
                        type: array
                        items:
                          type: string
                          format: uuid
                          pattern: >-
                            ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$
                    required:
                      - all
                      - teams
                      - projects
                      - environments
                    additionalProperties: false
                  expiresAt:
                    type: string
                required:
                  - id
                  - token
                  - name
                  - prefix
                  - permission
                  - scope
                  - expiresAt
                additionalProperties: false
      security:
        - apiKeyAuth: []
      x-codeSamples:
        - lang: bash
          label: cURL
          source: >-
            curl -X POST
            'http://localhost:8080/v1/workspace/ws_example/tokens/tok_example/rotate'
            \
              -H 'Authorization: Bearer ek_live_xxxxx'
        - lang: javascript
          label: TypeScript
          source: >-
            const response = await
            fetch('http://localhost:8080/v1/workspace/ws_example/tokens/tok_example/rotate',
            {
              method: 'POST',
              headers: {
                Authorization: 'Bearer ek_live_xxxxx',
              },
            });


            const data = await response.json();
        - lang: python
          label: Python
          source: |-
            import requests

            response = requests.post(
                'http://localhost:8080/v1/workspace/ws_example/tokens/tok_example/rotate',
                headers={
                    'Authorization': 'Bearer ek_live_xxxxx',
                },
            )

            data = response.json()
components:
  securitySchemes:
    apiKeyAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: >-
        API key authentication. Pass `Authorization: Bearer ek_live_xxxxx` on
        every request.

````