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

# Rotate a key

> Creates a new secret with the same name and permissions, and a lifetime as long as the original's, counted from now. The current secret keeps working for `expireCurrentIn` seconds, so you can deploy the new one first. A key may rotate itself, but never a key that holds a permission it does not. Needs `apiKey:write`.



## OpenAPI

````yaml POST /developer/v1/api-key/{id}/roll
openapi: 3.1.0
info:
  title: Compago API
  version: 1.0.0
  description: >-
    Public and private API endpoints for Compago's payment infrastructure. This
    specification currently includes endpoints for one-time payments. More
    endpoints will be added as the platform evolves.
servers:
  - url: https://demo-api-harmony.compago.com/api
  - url: https://api-harmony.compago.com/api
security: []
tags:
  - name: OneTimePayment
    description: Endpoints for creating and processing one-time payment links
  - name: PaymentMethod
    description: >-
      Endpoints for saving cards, charging saved payment methods, holding and
      capturing funds, and processing refunds
  - name: PaymentIntent
    description: >-
      Endpoints for creating and managing card-present payment intents for POS
      terminal integrations
  - name: Payments
    description: Read the payments your organization has taken
  - name: Subscriptions
    description: Read and manage recurring billing agreements
  - name: PaymentLinks
    description: Create, edit and retire hosted checkout links
  - name: Products
    description: Manage the catalogue behind product-based payment links
  - name: Promotions
    description: Read the promotions your organization funds or benefits from
  - name: Salespeople
    description: Read the point-of-sale operators in your organization
  - name: Organization
    description: Read your organization profile and its members
  - name: SavedCards
    description: Read saved payment methods and their payments
  - name: Payouts
    description: >-
      Read the transfers Compago sent to your bank accounts and what each one
      paid
  - name: Events
    description: >-
      Read the webhook events of the last 30 days, to reconcile after your
      endpoint was down
  - name: ApiKeys
    description: Manage your organization's API keys with a key that holds `apiKey:write`.
paths:
  /developer/v1/api-key/{id}/roll:
    post:
      tags:
        - ApiKeys
      summary: Rotate a key
      description: >-
        Creates a new secret with the same name and permissions, and a lifetime
        as long as the original's, counted from now. The current secret keeps
        working for `expireCurrentIn` seconds, so you can deploy the new one
        first. A key may rotate itself, but never a key that holds a permission
        it does not. Needs `apiKey:write`.
      operationId: rollApiKey
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: The key's id.
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                expireCurrentIn:
                  type: integer
                  minimum: 0
                  maximum: 604800
                  default: 86400
                  description: >-
                    Seconds the current secret keeps working. `0` ends it now.
                    At most 7 days.
            example:
              expireCurrentIn: 86400
      responses:
        '201':
          description: >-
            Rotated. The new key, with its secret, and until when the old one
            works.
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/PublicApiKeyWithSecret'
                  - type: object
                    properties:
                      previous:
                        type: object
                        properties:
                          id:
                            type: string
                            format: uuid
                          expiresAt:
                            type: string
                            format: date-time
                            description: When the old secret stops working.
                        required:
                          - id
                          - expiresAt
                    required:
                      - previous
        '401':
          description: >-
            Unauthorized. The key is missing or unknown (`UNAUTHORIZED`),
            expired (`API_KEY_EXPIRED`), turned off (`API_KEY_DISABLED`) or
            revoked (`API_KEY_REVOKED`).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicError'
        '403':
          description: >-
            Forbidden. The key does not hold `apiKey:write`
            (`INSUFFICIENT_SCOPE`), or tried to give permissions it does not
            hold (`SCOPE_NOT_GRANTABLE`).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicError'
        '404':
          description: >-
            Not found. No key with this id in your organization, or it was
            revoked.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicError'
        '409':
          description: >-
            Conflict. The key was already rotated (`API_KEY_ALREADY_ROLLED`):
            rotate its replacement.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicError'
        '429':
          description: >-
            Rate limit exceeded. See the `Retry-After` and `X-RateLimit-*`
            headers.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicError'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    PublicApiKeyWithSecret:
      allOf:
        - $ref: '#/components/schemas/PublicApiKey'
        - type: object
          properties:
            key:
              type: string
              description: >-
                The whole key, starting with `cmp_`. Shown only in this
                response: store it now.
          required:
            - key
    PublicError:
      type: object
      properties:
        message:
          type: string
          description: Human-readable description.
        code:
          type: string
          description: Stable machine-readable code. Branch on this, not on `message`.
      required:
        - message
    PublicApiKey:
      type: object
      description: >-
        An API key. Never its secret, which only the responses that create or
        rotate a key carry.
      properties:
        id:
          type: string
          format: uuid
        name:
          type:
            - string
            - 'null'
        start:
          type:
            - string
            - 'null'
          description: The first characters of the secret, e.g. `cmp_7Hk2`.
        lastFour:
          type:
            - string
            - 'null'
          description: >-
            The last four characters of the secret. `null` on keys created
            before they were recorded.
        status:
          type: string
          enum:
            - active
            - disabled
            - expired
        fullAccess:
          type: boolean
          description: >-
            `true` for a key created before permissions: it holds every
            permission but `apiKey:write`, including ones added later.
        permissions:
          type: array
          items:
            $ref: '#/components/schemas/ApiKeyPermission'
          description: What the key holds, each write with the reads it needs.
        expiresAt:
          type:
            - string
            - 'null'
          format: date-time
          description: When the key stops working. `null` if it never expires.
        lastUsedAt:
          type:
            - string
            - 'null'
          format: date-time
          description: The last request made with the key, to the minute.
        createdAt:
          type: string
          format: date-time
        replacedBy:
          type:
            - string
            - 'null'
          format: uuid
          description: >-
            Set once the key was rotated: the id of the key that replaced it.
            This one works until `expiresAt`.
      required:
        - id
        - name
        - start
        - lastFour
        - status
        - fullAccess
        - permissions
        - expiresAt
        - lastUsedAt
        - createdAt
        - replacedBy
    ApiKeyPermission:
      type: string
      enum:
        - payment:read
        - refund:write
        - oneTimePayment:read
        - oneTimePayment:write
        - paymentLink:read
        - subscription:read
        - paymentMethod:read
        - paymentMethod:write
        - paymentIntent:read
        - paymentIntent:write
        - terminal:read
        - salesperson:read
        - product:read
        - promotion:read
        - fee:read
        - payout:read
        - bankAccount:read
        - organization:read
        - member:read
        - apiKey:write
      description: >-
        A permission a key can hold. See [Key
        permissions](/get-started/api-key-permissions).
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.