> ## 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.

# Cancel contract

> Cancels a draft or active contract, and completes its active plan instances. For an active contract, Aira closes the current billing cycle on the day of the cancellation, prices it up to that day and moves its invoice to review, or issues it when the contract has `autoIssue` on, and cancels the other open billing cycles with their invoices that are not issued. Issued invoices stay as they are. The connected integrations receive the cancellation. Canceling a canceled contract leaves it as it is.

Requires the role `contracts:write`.



## OpenAPI

````yaml /api-reference/openapi.yaml post /v1/contracts/{id}/cancel
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/contracts/{id}/cancel:
    post:
      tags:
        - Contracts
      summary: Cancel contract
      description: >-
        Cancels a draft or active contract, and completes its active plan
        instances. For an active contract, Aira closes the current billing cycle
        on the day of the cancellation, prices it up to that day and moves its
        invoice to review, or issues it when the contract has `autoIssue` on,
        and cancels the other open billing cycles with their invoices that are
        not issued. Issued invoices stay as they are. The connected integrations
        receive the cancellation. Canceling a canceled contract leaves it as it
        is.


        Requires the role `contracts:write`.
      parameters:
        - schema:
            type: string
            format: uuid
          in: path
          name: id
          required: true
          description: Unique identifier for the contract.
      responses:
        '200':
          description: >-
            An agreement with an individual or an organization that bills plans,
            each through at most one active plan instance. It holds the term,
            the billing schedule, the usage scope, the payment accounts and the
            payment conditions.
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    format: uuid
                    description: Unique identifier for the contract.
                  contractNumber:
                    type: string
                    description: >-
                      The number of the contract, which Aira gives it on
                      creation from the prefix of its customer and the sequence
                      of the contracts of that customer.
                    examples:
                      - MERCA-CTR-01
                  customerId:
                    type: string
                    format: uuid
                    description: ID of the customer associated with this contract.
                  legalEntityId:
                    type:
                      - string
                      - 'null'
                    format: uuid
                    description: >-
                      ID of the legal entity associated with this contract.
                      Optional on create; defaults to the default legal entity
                      when absent.
                  legalEntity:
                    type: object
                    description: >-
                      The legal entity, a registered company, that issues the
                      invoices of the contract.
                    properties:
                      id:
                        type: string
                        format: uuid
                        description: >-
                          The unique identifier of the legal entity in our
                          system.
                      businessName:
                        type: string
                        description: >-
                          Registered business name (razão social) of the legal
                          entity.
                        examples:
                          - Padaria Central Ltda
                      tradeName:
                        type:
                          - string
                          - 'null'
                        description: >-
                          Trade name (nome fantasia) of the legal entity. Null
                          when absent.
                        examples:
                          - Padaria Central
                    required:
                      - id
                      - businessName
                      - tradeName
                    additionalProperties: false
                  startDate:
                    type: string
                    format: date
                    description: The first day of the term of the contract.
                  endDate:
                    type:
                      - string
                      - 'null'
                    format: date
                    description: >-
                      The last day of the term of the contract, or null when the
                      contract has no end date.
                  retroactiveDate:
                    type:
                      - string
                      - 'null'
                    format: date
                    description: >-
                      The date since which the contract was served before it
                      reached Aira, or null. Aira records invoices for the
                      billing cycles since that date but does not collect them,
                      because they were charged elsewhere.
                  invoicingStartDate:
                    type:
                      - string
                      - 'null'
                    format: date
                    description: >-
                      Read-only. Start date of the first billing cycle Aira
                      invoices for this contract, recorded when it is activated:
                      the cycle containing the retroactive date when one is set,
                      otherwise the cycle running on the activation day, or the
                      contract start when that is still ahead. Null while the
                      contract is a draft.
                  status:
                    type: string
                    enum:
                      - active
                      - canceled
                      - completed
                      - draft
                    description: Current status of the contract.
                  rateAdjustmentIndex:
                    type:
                      - string
                      - 'null'
                    enum:
                      - none
                      - igpm
                      - ipca
                      - other
                      - null
                    description: >-
                      Reference index (e.g. IPCA) used to filter contracts when
                      applying a mass adjustment on contracts.
                  customFields:
                    type: object
                    description: >-
                      Custom fields that can be associated with the entity. The
                      fields must be previously created in the system before
                      they can be used.
                    additionalProperties:
                      anyOf:
                        - type: string
                        - type: array
                          items:
                            type: string
                    default: {}
                    examples:
                      - customField1: value1
                        customField2:
                          - value2
                          - value3
                  taxRegimeId:
                    type:
                      - string
                      - 'null'
                    format: uuid
                    description: >-
                      ID of the tax regime applied to invoices generated from
                      this contract. Null when no regime is attached.
                  invoiceAllocationStrategy:
                    type: string
                    enum:
                      - single
                      - percent_split
                      - subsidiary_usage_split
                    description: >-
                      How each billing act of the contract becomes invoices:
                      `single` makes one invoice, `percent_split` makes one per
                      payment account by fixed percentages, and
                      `subsidiary_usage_split` makes one per payment account by
                      the share of the usage of its customer.
                  includeNewSubsidiariesOnUsageScope:
                    type: boolean
                    description: >-
                      Whether future subsidiaries are automatically included in
                      usage scope.
                  autoIssue:
                    type: boolean
                    description: >-
                      When true, invoices produced at billing-cycle close are
                      issued automatically instead of waiting in review.
                      Defaults to false when omitted; omitting it on update
                      leaves the current value unchanged.
                  usageScopes:
                    type: array
                    items:
                      type: object
                      description: >-
                        A customer of the usage scope of the contract, whose
                        usage and license balances the contract bills.
                      properties:
                        customerId:
                          type: string
                          format: uuid
                          description: Customer ID that contributes usage to this contract.
                      required:
                        - customerId
                      additionalProperties: false
                    minItems: 1
                    description: >-
                      The usage scope of the contract: the customers whose usage
                      and license balances it bills, which are the individual
                      alone, or a set of the organization and its subsidiaries.
                    uniqueItems: true
                  allocations:
                    type: array
                    description: >-
                      The contract allocation: the payment accounts that receive
                      the invoices of the contract.
                    items:
                      type: object
                      description: >-
                        A payment account that receives invoices of the
                        contract, with its share of each billing act.
                      properties:
                        paymentAccountId:
                          type: string
                          format: uuid
                          description: ID of the payment account.
                        allocationPercentage:
                          type:
                            - string
                            - 'null'
                          description: >-
                            The percentage of each billing act that the payment
                            account receives, from 0 to 100 with up to 6 decimal
                            places, or null, which only a contract that splits
                            its invoices by subsidiary usage allows.
                          examples:
                            - '50.000000'
                      required:
                        - paymentAccountId
                        - allocationPercentage
                      additionalProperties: false
                    minItems: 1
                  billingSettings:
                    type:
                      - object
                      - 'null'
                    description: >-
                      The contract minimum: the least that the contract bills in
                      a billing cycle, across all its plans. When its plans
                      total less, the closing invoice adds the difference.
                    properties:
                      invoiceMinimumAmount:
                        type: number
                        description: >-
                          The least amount, in cents, that the contract bills in
                          a billing cycle across all its plans.
                        minimum: 0
                      productId:
                        type: string
                        format: uuid
                        description: >-
                          Product ID to use for contract minimum amount line
                          items.
                    required:
                      - invoiceMinimumAmount
                      - productId
                    additionalProperties: false
                  billingSchedule:
                    type: object
                    description: >-
                      How the billing cycles of the contract repeat: every month
                      or every week, from the billing day of the contract.
                    properties:
                      periodUnit:
                        type: string
                        enum:
                          - week
                          - month
                        description: >-
                          The calendar the contract closes on: month bills on a
                          day of the month, week on a weekday. Every plan on the
                          contract bills on this family; a plan from the other
                          family belongs on a second contract. A draft can
                          change it only while it has no plans.
                      anchorSource:
                        type: string
                        enum:
                          - based_on_contract_start_date
                          - explicit
                          - first_day_of_month
                        description: >-
                          The label the contract screen shows for the billing
                          day. The engine bills on anchorDay alone, so
                          first_day_of_month only describes a schedule that
                          already opens on day 1.
                      anchorDay:
                        type: integer
                        minimum: 1
                        maximum: 31
                        description: >-
                          The billing day, read per family: day of month (1-31)
                          on the month family, day of week
                          (1=Sunday...7=Saturday) on the week family.
                    required:
                      - periodUnit
                      - anchorSource
                      - anchorDay
                    allOf:
                      - if:
                          type: object
                          properties:
                            anchorSource:
                              enum:
                                - first_day_of_month
                          required:
                            - anchorSource
                        then:
                          type: object
                          properties:
                            anchorDay:
                              enum:
                                - 1
                        errorMessage: >-
                          must pair first_day_of_month with anchorDay 1; use
                          another anchorSource to bill on a different day
                      - if:
                          type: object
                          properties:
                            periodUnit:
                              enum:
                                - week
                          required:
                            - periodUnit
                        then:
                          type: object
                          properties:
                            anchorDay:
                              type: integer
                              maximum: 7
                        errorMessage: >-
                          on the week calendar the billing day is a weekday, 1
                          (Sunday) to 7 (Saturday)
                      - if:
                          type: object
                          properties:
                            anchorSource:
                              enum:
                                - first_day_of_month
                          required:
                            - anchorSource
                        then:
                          type: object
                          properties:
                            periodUnit:
                              enum:
                                - month
                        errorMessage: >-
                          first_day_of_month is a month-calendar label; the week
                          calendar bills on a weekday
                    additionalProperties: false
                  paymentGatewaySettings:
                    type:
                      - object
                      - 'null'
                    description: >-
                      The payment conditions of the contract: how its invoices
                      are paid, with the payment method, and the due date as a
                      number of days after the issue or a fixed day of the
                      month.
                    properties:
                      paymentMethod:
                        type: string
                        enum:
                          - bolepix
                          - bank_slip
                          - pix
                          - credit_card
                          - bank_transfer
                        description: >-
                          Payment method to use for this contract. Must be
                          supported by the active payment provider.
                      dueDateMode:
                        type: string
                        enum:
                          - days_after_issue
                          - fixed_day
                        description: >-
                          How invoice due dates are derived: a day offset from
                          the issue date, or a fixed day of the month.
                        default: days_after_issue
                      dueOffsetDays:
                        type:
                          - number
                          - 'null'
                        minimum: 0
                        description: >-
                          Number of days after the issue date until payment is
                          due (0 = due on issue day). Used when dueDateMode is
                          days_after_issue.
                      dueDay:
                        type:
                          - number
                          - 'null'
                        minimum: 1
                        maximum: 31
                        description: >-
                          Day of the month invoices are due on, clamped to the
                          last day of shorter months. Used when dueDateMode is
                          fixed_day.
                      dueMonthOffset:
                        type: integer
                        enum:
                          - 0
                          - 1
                        description: >-
                          How many months after the issue month the fixed due
                          day falls on: 0 for the same month, 1 for the next.
                          Used when dueDateMode is fixed_day.
                        default: 0
                      rollDueDateToBusinessDay:
                        type: boolean
                        description: >-
                          Whether a due date landing on a weekend moves to the
                          next business day. Off keeps it on the day it falls.
                        default: true
                    required:
                      - paymentMethod
                      - dueDateMode
                    allOf:
                      - if:
                          properties:
                            dueDateMode:
                              enum:
                                - fixed_day
                          required:
                            - dueDateMode
                        then:
                          properties:
                            dueDay:
                              not:
                                enum:
                                  - null
                          required:
                            - dueDay
                        else:
                          properties:
                            dueOffsetDays:
                              not:
                                enum:
                                  - null
                          required:
                            - dueOffsetDays
                    additionalProperties: false
                  planInstances:
                    description: >-
                      The plan instances attached to the contract. While the
                      contract is draft or active only its active plan instances
                      are listed; once the contract is completed or canceled,
                      all of them are.
                    type: array
                    items:
                      type: object
                      description: >-
                        A plan put on the contract. It has its own versions, so
                        the prices of one contract can change while the plan
                        stays the same.
                      properties:
                        id:
                          description: >-
                            The unique identifier of the plan instance in our
                            system. Use it to fetch or update the plan instance.
                          type: string
                          format: uuid
                        planId:
                          description: >-
                            The unique identifier of the plan this instance was
                            created from.
                          type: string
                          format: uuid
                        name:
                          description: The name of the plan this instance was created from.
                          type: string
                          examples:
                            - Plano Essencial
                        status:
                          description: The current status of the plan instance.
                          type: string
                          enum:
                            - active
                            - canceled
                            - completed
                      required:
                        - id
                        - planId
                        - name
                        - status
                      additionalProperties: false
                required:
                  - id
                  - contractNumber
                  - customerId
                  - startDate
                  - endDate
                  - retroactiveDate
                  - invoicingStartDate
                  - status
                  - rateAdjustmentIndex
                  - customFields
                  - invoiceAllocationStrategy
                  - includeNewSubsidiariesOnUsageScope
                  - usageScopes
                  - allocations
                  - billingSchedule
                  - planInstances
                additionalProperties: false
        '400':
          description: >-
            The request cannot succeed as sent.


            - `json_schema_validation_error`: a path parameter breaks the schema
            of the endpoint.

            - `contract_cannot_be_updated`: the contract is completed.

            - `invalid_proration_usage_scope`: the contract has a current
            billing cycle, which the cancellation prices, while its usage scope
            holds more than one customer and a plan of the contract charges for
            a resource whose billing model is proration.

            - `invalid_credit_ledger_entry_for_credit_purchase`: the contract
            has a current billing cycle, which the cancellation prices, while
            that billing cycle consumes more credits than a credit pool of the
            customer holds and the credit package that tops up that pool holds
            zero credits.
          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
                      - contract_cannot_be_updated
                      - invalid_proration_usage_scope
                      - invalid_credit_ledger_entry_for_credit_purchase
                  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
                contract_cannot_be_updated:
                  value:
                    message: <string>
                    code: contract_cannot_be_updated
                invalid_proration_usage_scope:
                  value:
                    message: <string>
                    code: invalid_proration_usage_scope
                invalid_credit_ledger_entry_for_credit_purchase:
                  value:
                    message: <string>
                    code: invalid_credit_ledger_entry_for_credit_purchase
        '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: <string>
                    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 IP of the request is not among the IPs that
            your API keys accept.
          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 contracts:write can not be satisfied
                    code: bad_auth
                invalid_api_key:
                  value:
                    message: <string>
                    code: invalid_api_key
                deactivated_api_key:
                  value:
                    message: <string>
                    code: deactivated_api_key
                revoked_api_key:
                  value:
                    message: <string>
                    code: revoked_api_key
                expired_api_key:
                  value:
                    message: <string>
                    code: expired_api_key
                ip_not_allowed:
                  value:
                    message: <string>
                    code: ip_not_allowed
        '404':
          description: |-
            A record that the request names does not exist.

            - `contract_not_found`: no contract 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:
                      - contract_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:
                contract_not_found:
                  value:
                    message: <string>
                    code: contract_not_found
        '503':
          description: >-
            A service that the request needs is unavailable.


            - `stale_events_writer`: the contract has a current billing cycle,
            which the cancellation prices, while a write of events has run for
            longer than any write of events may last.
          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:
                      - stale_events_writer
                  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:
                stale_events_writer:
                  value:
                    message: <string>
                    code: stale_events_writer
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.