> ## 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 plan instances to latest plan version

> Moves each plan instance of the body to the active plan version of its plan: a new plan instance version, with the plan charges of that plan version and the reason created_from_plan_version, becomes its active plan instance version. A plan instance whose active plan instance version already comes from that plan version, with that reason, stays as it is. The request updates all the plan instances or none, and answers each plan instance that it selected.

Requires the role `plan_instances:write`.



## OpenAPI

````yaml /api-reference/openapi.yaml post /v1/plan-instances/update-to-latest-plan-version
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/plan-instances/update-to-latest-plan-version:
    post:
      tags:
        - Plan Instances
      summary: Update plan instances to latest plan version
      description: >-
        Moves each plan instance of the body to the active plan version of its
        plan: a new plan instance version, with the plan charges of that plan
        version and the reason created_from_plan_version, becomes its active
        plan instance version. A plan instance whose active plan instance
        version already comes from that plan version, with that reason, stays as
        it is. The request updates all the plan instances or none, and answers
        each plan instance that it selected.


        Requires the role `plan_instances:write`.
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                includePlanInstanceIds:
                  description: >-
                    The unique identifiers of the plan instances to update, at
                    most 10,000. Each plan instance must be active.
                  type: array
                  items:
                    type: string
                    format: uuid
                  minItems: 1
                  maxItems: 10000
                  uniqueItems: true
                excludePlanInstanceIds:
                  description: >-
                    The unique identifiers of the plan instances to leave as
                    they are, at most 10,000.
                  type: array
                  items:
                    type: string
                    format: uuid
                  maxItems: 10000
                  uniqueItems: true
                selectAll:
                  description: >-
                    When true, the request updates the active plan instances of
                    the plan of `selectFilters`, at most 10,000, in place of the
                    ones of `includePlanInstanceIds`.
                  type: boolean
                selectFilters:
                  description: >-
                    The plan whose active plan instances the request updates
                    when `selectAll` is true.
                  type: object
                  properties:
                    planId:
                      description: The unique identifier of the plan.
                      type: string
                      format: uuid
                  required:
                    - planId
                  additionalProperties: false
              anyOf:
                - required:
                    - includePlanInstanceIds
                - required:
                    - selectAll
                    - selectFilters
              additionalProperties: false
        description: >-
          The plan instances to update: the ones of `includePlanInstanceIds`, or
          the active plan instances of the plan of `selectFilters` when
          `selectAll` is true.
      responses:
        '200':
          description: >-
            The plan instances that the request selected, as they are after the
            update.
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items:
                      type: object
                      description: >-
                        Schema representing a plan instance, a plan put on one
                        contract, without the charges of its active plan
                        instance version. Fetch the plan instance by id to read
                        its charges.
                      properties:
                        id:
                          description: >-
                            The unique identifier of the plan instance in our
                            system.
                          type: string
                          format: uuid
                        contractId:
                          description: >-
                            The unique identifier of the contract that the plan
                            instance belongs to.
                          type: string
                          format: uuid
                        planId:
                          description: >-
                            The unique identifier of the plan that the plan
                            instance comes from.
                          type: string
                          format: uuid
                        status:
                          description: >-
                            The status of the plan instance: active (billed in
                            the cycles of the contract), completed (reached its
                            end) or canceled (stopped before its end).
                          type: string
                          enum:
                            - active
                            - canceled
                            - completed
                        activePlanInstanceVersionId:
                          description: >-
                            The unique identifier of the plan instance version
                            that billing uses.
                          type: string
                          format: uuid
                        activePlanVersionId:
                          description: >-
                            The unique identifier of the plan version that the
                            active plan instance version comes from.
                          type: string
                          format: uuid
                        activePlanInstanceVersionReason:
                          description: >-
                            Why the active plan instance version exists:
                            created_from_plan_version (it comes from a plan
                            version of the plan), duplicated_from_contract (a
                            copy of a plan instance of another contract),
                            manual_override (an update of the charges of the
                            plan instance), readjustment (a rate adjustment) or
                            rollback (a restore of an earlier version).
                          type: string
                          enum:
                            - created_from_plan_version
                            - duplicated_from_contract
                            - manual_override
                            - readjustment
                            - rollback
                        plan:
                          description: The plan that the plan instance comes from.
                          type: object
                          properties:
                            id:
                              description: The unique identifier of the plan.
                              type: string
                              format: uuid
                            name:
                              description: The name of the plan.
                              type: string
                              example: Plano Essencial
                            description:
                              description: >-
                                The description of the plan, or null when it has
                                none.
                              type:
                                - 'null'
                                - string
                              example: Assinatura mensal com entrega diária de pães.
                            productId:
                              type: string
                              format: uuid
                              description: >-
                                The unique identifier of the product that the
                                plan belongs to.
                          required:
                            - id
                            - name
                            - description
                            - productId
                          additionalProperties: false
                      required:
                        - id
                        - contractId
                        - planId
                        - status
                        - activePlanInstanceVersionId
                        - activePlanVersionId
                        - activePlanInstanceVersionReason
                        - plan
                      additionalProperties: false
                    description: A list of items.
                required:
                  - items
                additionalProperties: false
        '400':
          description: >-
            The request cannot succeed as sent.


            - `json_schema_validation_error`: the body breaks the schema of the
            endpoint.

            - `missing_plan_instance_ids`: `selectAll` is false and the body has
            no `includePlanInstanceIds`.

            - `plan_instance_not_active`: a plan instance of
            `includePlanInstanceIds` is completed or canceled.

            - `invalid_proration_usage_scope`: the active plan version of the
            plan of a plan instance has a usage-based charge on a resource with
            the billing model `proration`, and the usage scope of the contract
            of the plan instance has more than one customer.

            - `invalid_license_proration_allocation`: the active plan version of
            the plan of a plan instance has a license-based charge with the
            billing model `proration`, and the contract of the plan instance
            splits its invoices by the share of the usage of each customer.

            - `mixed_billing_frequency_family`: the billing frequencies of the
            plan charges of the active plan version of the plan of a plan
            instance are in weeks and the billing schedule of the contract of
            the plan instance repeats every month, or the reverse.
          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
                      - missing_plan_instance_ids
                      - plan_instance_not_active
                      - invalid_proration_usage_scope
                      - invalid_license_proration_allocation
                      - mixed_billing_frequency_family
                  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: body must be object
                    code: json_schema_validation_error
                missing_plan_instance_ids:
                  value:
                    message: Either selectAll or planInstanceIds must be provided
                    code: missing_plan_instance_ids
                plan_instance_not_active:
                  value:
                    message: plan instance must be active
                    code: plan_instance_not_active
                invalid_proration_usage_scope:
                  value:
                    message: >-
                      proration metrics are not supported when billing cycle
                      usage scope has more than one customer
                    code: invalid_proration_usage_scope
                invalid_license_proration_allocation:
                  value:
                    message: >-
                      prorated license charges are not supported on contracts
                      that split invoices by subsidiary usage
                    code: invalid_license_proration_allocation
                mixed_billing_frequency_family:
                  value:
                    message: >-
                      the billing frequencies of the plan charges of the active
                      plan version of the plan of a plan instance are in weeks
                      and the billing schedule of the contract of the plan
                      instance repeats every month, or the reverse
                    code: mixed_billing_frequency_family
        '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.

            - `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 plan_instances:write 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.


            - `plan_instance_not_found`: no plan instance of the tenant has an
            id of `includePlanInstanceIds`, or `excludePlanInstanceIds` also
            lists it.
          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:
                      - plan_instance_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:
                plan_instance_not_found:
                  value:
                    message: plan instance not found
                    code: plan_instance_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.