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

# Update API key

> Changes the name, the roles, the status or the expiry date of another API key of the tenant, and keeps each field that the body leaves out. The next request of the API key runs with the change, so a key that becomes `deactivated` or `revoked` stops working at once.

Requires the role `api_keys:admin`.



## OpenAPI

````yaml /api-reference/openapi.yaml patch /v1/api-keys/{id}
openapi: 3.1.0
info:
  title: API Reference
  version: '1.0'
  description: Aira API Reference
  x-logo:
    url: https://static.useaira.com/images/airalogo.svg
    backgroundColor: '#FFFFFF'
    altText: Aira Logo
servers:
  - url: https://api.useaira.com
    description: API base URL
security:
  - ApiKey: []
paths:
  /v1/api-keys/{id}:
    patch:
      tags:
        - Api Keys
      summary: Update API key
      description: >-
        Changes the name, the roles, the status or the expiry date of another
        API key of the tenant, and keeps each field that the body leaves out.
        The next request of the API key runs with the change, so a key that
        becomes `deactivated` or `revoked` stops working at once.


        Requires the role `api_keys:admin`.
      parameters:
        - schema:
            type: string
            format: uuid
          in: path
          name: id
          required: true
          description: The unique identifier of the API key.
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                friendlyName:
                  type: string
                  description: >-
                    The name that tells the API key apart from the other API
                    keys of the tenant, such as the name of the system that uses
                    it.
                  example: ERP da Padaria Central
                roles:
                  type: array
                  items:
                    type: string
                    enum:
                      - contracts:admin
                      - contracts:read
                      - contracts:write
                      - customers:read
                      - customers:write
                      - dunning:read
                      - dunning:write
                      - emails:read
                      - events:read
                      - events:write
                      - integrations:read
                      - integrations:write
                      - invoices:read
                      - invoices:write
                      - items:read
                      - items:write
                      - legal_entities:read
                      - licenses:read
                      - licenses:write
                      - payment_accounts:read
                      - payment_accounts:write
                      - payments:read
                      - plan_instance_versions:read
                      - plan_instance_versions:write
                      - plan_instances:read
                      - plan_instances:write
                      - plans:read
                      - products:read
                      - products:write
                      - resources:read
                      - resources:write
                      - tenants:read
                      - watchtower:write
                  description: >-
                    The roles of the API key, each a resource and a permission,
                    such as `invoices:read`, which set what the API key can do.
                    A `write` role does not cover `read`.
                  example:
                    - invoices:read
                    - invoices:write
                expireAt:
                  type: string
                  format: date-time
                  description: The instant, in UTC, when the API key stops working.
                  example: '2027-01-01T00:00:00.000Z'
                status:
                  type: string
                  enum:
                    - active
                    - deactivated
                    - revoked
                  description: >-
                    The status of the API key. Only an `active` API key can call
                    the public API.
              required: []
              additionalProperties: false
        description: >-
          The fields of the API key to change. The API key keeps each field that
          the body leaves out.
      responses:
        '200':
          description: >-
            An API key of the tenant: a key that a system of the tenant sends in
            the `X-API-KEY` header to call the public API, with the roles that
            set what the system can do. Aira shows the key itself only in the
            reply that creates the API key.
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    format: uuid
                    description: The unique identifier of the API key.
                  friendlyName:
                    type: string
                    description: >-
                      The name that tells the API key apart from the other API
                      keys of the tenant, such as the name of the system that
                      uses it.
                    example: ERP da Padaria Central
                  roles:
                    type: array
                    items:
                      type: string
                    description: >-
                      The roles of the API key, each a resource and a
                      permission, such as `invoices:read`, which set what the
                      API key can do. A `write` role does not cover `read`.
                    example:
                      - invoices:read
                      - invoices:write
                  status:
                    type: string
                    enum:
                      - active
                      - deactivated
                      - revoked
                    description: >-
                      The status of the API key. Only an `active` API key can
                      call the public API.
                  expireAt:
                    type: string
                    format: date-time
                    description: The instant, in UTC, when the API key stops working.
                    example: '2027-01-01T00:00:00.000Z'
                required:
                  - id
                  - friendlyName
                  - roles
                  - status
                  - expireAt
                additionalProperties: false
        '400':
          description: >-
            The request cannot succeed as sent.


            - `json_schema_validation_error`: a path parameter or the body
            breaks the schema of the endpoint.
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    description: >-
                      A sentence for a person that says what failed. It can
                      change, so a system compares the code instead.
                  code:
                    type: string
                    description: >-
                      The identifier of the error, which a system compares to
                      decide what to do. It never changes.
                    enum:
                      - json_schema_validation_error
                  details:
                    oneOf:
                      - type: object
                        additionalProperties: true
                      - type: array
                    description: >-
                      The data of the error, when it has any, such as the fields
                      that failed the validation.
                  causations:
                    type: array
                    description: >-
                      The errors that caused this one, when several did, each
                      with its own message, code and details.
                    items:
                      type: object
                      properties:
                        message:
                          type: string
                          description: A sentence for a person that says what failed.
                        code:
                          type: string
                          description: The identifier of the error.
                        details:
                          type: object
                          additionalProperties: true
                          description: The data of the error, when it has any.
                      required:
                        - message
                        - code
                      additionalProperties: false
                required:
                  - message
                  - code
                additionalProperties: false
              examples:
                json_schema_validation_error:
                  value:
                    message: '''id'' must match format "uuid"'
                    code: json_schema_validation_error
        '401':
          description: >-
            The request carries no API key.


            - `no_authorization`: the request carries no API key in the
            `X-API-KEY` header.
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    description: >-
                      A sentence for a person that says what failed. It can
                      change, so a system compares the code instead.
                  code:
                    type: string
                    description: >-
                      The identifier of the error, which a system compares to
                      decide what to do. It never changes.
                    enum:
                      - no_authorization
                  details:
                    oneOf:
                      - type: object
                        additionalProperties: true
                      - type: array
                    description: >-
                      The data of the error, when it has any, such as the fields
                      that failed the validation.
                  causations:
                    type: array
                    description: >-
                      The errors that caused this one, when several did, each
                      with its own message, code and details.
                    items:
                      type: object
                      properties:
                        message:
                          type: string
                          description: A sentence for a person that says what failed.
                        code:
                          type: string
                          description: The identifier of the error.
                        details:
                          type: object
                          additionalProperties: true
                          description: The data of the error, when it has any.
                      required:
                        - message
                        - code
                      additionalProperties: false
                required:
                  - message
                  - code
                additionalProperties: false
              examples:
                no_authorization:
                  value:
                    message: No authorization provided
                    code: no_authorization
        '403':
          description: >-
            The API key cannot call the endpoint.


            - `bad_auth`: the API key does not hold the role that the endpoint
            requires; or the `id` names the calling API key, or the API key of
            the `id` holds a role that only Aira's team grants and the body does
            more than set `status` to `revoked`.

            - `invalid_api_key`: the API key does not exist.

            - `deactivated_api_key`: the API key is deactivated.

            - `revoked_api_key`: the API key is revoked.

            - `expired_api_key`: the API key is past its expiry date.

            - `ip_not_allowed`: the tenant does not allow the IP of the request.
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    description: >-
                      A sentence for a person that says what failed. It can
                      change, so a system compares the code instead.
                  code:
                    type: string
                    description: >-
                      The identifier of the error, which a system compares to
                      decide what to do. It never changes.
                    enum:
                      - bad_auth
                      - invalid_api_key
                      - deactivated_api_key
                      - revoked_api_key
                      - expired_api_key
                      - ip_not_allowed
                  details:
                    oneOf:
                      - type: object
                        additionalProperties: true
                      - type: array
                    description: >-
                      The data of the error, when it has any, such as the fields
                      that failed the validation.
                  causations:
                    type: array
                    description: >-
                      The errors that caused this one, when several did, each
                      with its own message, code and details.
                    items:
                      type: object
                      properties:
                        message:
                          type: string
                          description: A sentence for a person that says what failed.
                        code:
                          type: string
                          description: The identifier of the error.
                        details:
                          type: object
                          additionalProperties: true
                          description: The data of the error, when it has any.
                      required:
                        - message
                        - code
                      additionalProperties: false
                required:
                  - message
                  - code
                additionalProperties: false
              examples:
                bad_auth:
                  value:
                    message: role api_keys:admin can not be satisfied
                    code: bad_auth
                invalid_api_key:
                  value:
                    message: Invalid API key
                    code: invalid_api_key
                deactivated_api_key:
                  value:
                    message: Deactivated API key
                    code: deactivated_api_key
                revoked_api_key:
                  value:
                    message: Revoked API key
                    code: revoked_api_key
                expired_api_key:
                  value:
                    message: Expired API key
                    code: expired_api_key
                ip_not_allowed:
                  value:
                    message: IP not allowed
                    code: ip_not_allowed
        '404':
          description: |-
            A record that the request names does not exist in the tenant.

            - `api_key_not_found`: no API key of the tenant has the `id`.
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    description: >-
                      A sentence for a person that says what failed. It can
                      change, so a system compares the code instead.
                  code:
                    type: string
                    description: >-
                      The identifier of the error, which a system compares to
                      decide what to do. It never changes.
                    enum:
                      - api_key_not_found
                  details:
                    oneOf:
                      - type: object
                        additionalProperties: true
                      - type: array
                    description: >-
                      The data of the error, when it has any, such as the fields
                      that failed the validation.
                  causations:
                    type: array
                    description: >-
                      The errors that caused this one, when several did, each
                      with its own message, code and details.
                    items:
                      type: object
                      properties:
                        message:
                          type: string
                          description: A sentence for a person that says what failed.
                        code:
                          type: string
                          description: The identifier of the error.
                        details:
                          type: object
                          additionalProperties: true
                          description: The data of the error, when it has any.
                      required:
                        - message
                        - code
                      additionalProperties: false
                required:
                  - message
                  - code
                additionalProperties: false
              examples:
                api_key_not_found:
                  value:
                    message: api key not found
                    code: api_key_not_found
components:
  securitySchemes:
    ApiKey:
      type: apiKey
      description: API Key Authentication.
      name: X-API-KEY
      in: header

````

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