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

# Duplicate contract

> Creates a draft contract with the settings of a contract in any status, and copies the latest plan instance of each of its plans: from its active plan instances when the contract is active, and from all of them otherwise. The draft gets a contract number of its own, and leaves out the retroactive date when the end date of the contract has passed.

Requires the role `contracts:write`.



## OpenAPI

````yaml /api-reference/openapi.yaml post /v1/contracts/{id}/duplicate
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}/duplicate:
    post:
      tags:
        - Contracts
      summary: Duplicate contract
      description: >-
        Creates a draft contract with the settings of a contract in any status,
        and copies the latest plan instance of each of its plans: from its
        active plan instances when the contract is active, and from all of them
        otherwise. The draft gets a contract number of its own, and leaves out
        the retroactive date when the end date of the contract has passed.


        Requires the role `contracts:write`.
      parameters:
        - schema:
            type: string
            format: uuid
          in: path
          name: id
          required: true
          description: Unique identifier for the contract.
      responses:
        '201':
          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.
                    example: MERCA-CTR-01
                  customerId:
                    type: string
                    format: uuid
                    description: ID of the customer associated with this contract.
                  legalEntityId:
                    type: string
                    format: uuid
                    nullable: true
                    description: >-
                      ID of the legal entity associated with this contract.
                      Optional on create; defaults to the tenant's default legal
                      entity when absent.
                  legalEntity:
                    type: object
                    description: >-
                      The legal entity that issues the invoices of the contract:
                      a registered company of the tenant.
                    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.
                        example: Padaria Central Ltda
                      tradeName:
                        type: string
                        nullable: true
                        description: >-
                          Trade name (nome fantasia) of the legal entity. Null
                          when absent.
                        example: 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
                    format: date
                    nullable: true
                    description: >-
                      The last day of the term of the contract, or null when the
                      contract has no end date.
                  retroactiveDate:
                    type: string
                    format: date
                    nullable: true
                    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
                    format: date
                    nullable: true
                    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:
                      - 'null'
                      - string
                    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: {}
                    example:
                      customField1: value1
                      customField2:
                        - value2
                        - value3
                  taxRegimeId:
                    type: string
                    format: uuid
                    nullable: true
                    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
                          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.
                          nullable: true
                          example: '50.000000'
                      required:
                        - paymentAccountId
                        - allocationPercentage
                      additionalProperties: false
                    minItems: 1
                  billingSettings:
                    type: object
                    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
                    nullable: true
                  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
                    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 tenant active payment gateway.
                      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
                        minimum: 0
                        nullable: true
                        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
                        minimum: 1
                        maximum: 31
                        nullable: true
                        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
                    nullable: true
                  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
                          example: 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.

            - `tax_regime_required`: the tenant has the tax regime module on and
            the contract has no tax regime.

            - `customer_is_already_archived`: the customer of the contract is
            archived, or the usage scope of the contract names an archived
            subsidiary of that customer.

            - `invalid_retroactive_date`: the retroactive date of the contract
            falls in a month more than three years before the current month.

            - `contract_and_payment_account_must_belong_to_the_same_customer`: a
            payment account of the contract belongs to a subsidiary that is now
            archived.

            - `contract_without_payment_gateway_settings`: the tenant requires
            payment conditions on every contract and the contract has none.

            - `mixed_billing_frequency_family`: the plan instances that the copy
            takes have plan charges with billing frequencies in both months and
            weeks, or in a unit other than that of the billing schedule of the
            contract.
          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
                      - tax_regime_required
                      - customer_is_already_archived
                      - invalid_retroactive_date
                      - >-
                        contract_and_payment_account_must_belong_to_the_same_customer
                      - contract_without_payment_gateway_settings
                      - 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: '''id'' must match format "uuid"'
                    code: json_schema_validation_error
                tax_regime_required:
                  value:
                    message: >-
                      tax regime is required for contracts when the tax regime
                      module is enabled
                    code: tax_regime_required
                customer_is_already_archived:
                  value:
                    message: customer is archived
                    code: customer_is_already_archived
                invalid_retroactive_date:
                  value:
                    message: Retroactive date cannot be before start date
                    code: invalid_retroactive_date
                contract_and_payment_account_must_belong_to_the_same_customer:
                  value:
                    message: >-
                      contract and payment account must belong to contract owner
                      or its subsidiaries
                    code: >-
                      contract_and_payment_account_must_belong_to_the_same_customer
                contract_without_payment_gateway_settings:
                  value:
                    message: contract without payment gateway settings
                    code: contract_without_payment_gateway_settings
                mixed_billing_frequency_family:
                  value:
                    message: >-
                      the plan instances that the copy takes have plan charges
                      with billing frequencies in both months and weeks, or in a
                      unit other than that of the billing schedule of the
                      contract
                    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 contracts: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.


            - `contract_not_found`: no contract of the tenant has the `id`.

            - `tax_regime_not_found`: the tax regime of the contract is
            archived.

            - `payment_account_not_found`: a payment account of the contract is
            archived.
          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
                      - tax_regime_not_found
                      - payment_account_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: contract not found
                    code: contract_not_found
                tax_regime_not_found:
                  value:
                    message: >-
                      tax regime version {taxRegimeVersionId} not found
                      (snapshotted on invoice {id})
                    code: tax_regime_not_found
                payment_account_not_found:
                  value:
                    message: payment account not found
                    code: payment_account_not_found
        '422':
          description: >-
            An outside service refuses the data of the request.


            - `incompatible_payment_method_for_provider`: the payment provider
            of the tenant does not take the payment method of the contract.
          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:
                      - incompatible_payment_method_for_provider
                  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:
                incompatible_payment_method_for_provider:
                  value:
                    message: >-
                      payment method {method} is not supported by gateway
                      {activeProvider}
                    code: incompatible_payment_method_for_provider
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.