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

# Replace revenue traceabilities

> Replaces the revenue traceabilities of a contract with the items sent, and returns them. An item with the id of a revenue traceability of the contract for the same product keeps that record, with the dates, custom fields and attributions sent. Any other item creates a revenue traceability with an id of its own, and the request deletes each revenue traceability of the contract that no item keeps. The attributions of an item follow the same rule inside it. The list of the revenue traceabilities of the contract, and the revenue items, then read only the revenue traceabilities that the reply returns for the contract.

Requires the role `contracts:write`.



## OpenAPI

````yaml /api-reference/openapi.yaml put /v1/revenue-traceability/{contractId}
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/revenue-traceability/{contractId}:
    put:
      tags:
        - Revenue Traceability
      summary: Replace revenue traceabilities
      description: >-
        Replaces the revenue traceabilities of a contract with the items sent,
        and returns them. An item with the id of a revenue traceability of the
        contract for the same product keeps that record, with the dates, custom
        fields and attributions sent. Any other item creates a revenue
        traceability with an id of its own, and the request deletes each revenue
        traceability of the contract that no item keeps. The attributions of an
        item follow the same rule inside it. The list of the revenue
        traceabilities of the contract, and the revenue items, then read only
        the revenue traceabilities that the reply returns for the contract.


        Requires the role `contracts:write`.
      parameters:
        - schema:
            type: string
            format: uuid
          in: path
          name: contractId
          required: true
          description: >-
            The unique identifier of the contract whose revenue traceabilities
            the items replace.
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                items:
                  type: array
                  items:
                    type: object
                    description: >-
                      A revenue traceability: a dated record that tags the
                      revenue of a product that a contract bills with the
                      tenant's custom fields. Its attributions are dated records
                      inside it whose custom fields name who takes part in that
                      revenue.
                    properties:
                      id:
                        type: string
                        format: uuid
                        description: >-
                          The unique identifier of the revenue traceability in
                          our system.
                      productId:
                        type: string
                        format: uuid
                        description: >-
                          The unique identifier of the product whose revenue the
                          record tags.
                      startDate:
                        type: string
                        format: date
                        description: The first day that the record covers.
                      endDate:
                        type: string
                        format: date
                        nullable: true
                        description: >-
                          The last day that the record covers. Null when the
                          record has no end.
                      customFields:
                        type: object
                        description: >-
                          The values of the custom fields of revenue
                          traceabilities on the revenue traceability, keyed by
                          the key of each custom field.
                        additionalProperties:
                          anyOf:
                            - type: string
                            - type: array
                              items:
                                type: string
                        default: {}
                        example:
                          customField1: value1
                          customField2:
                            - value2
                            - value3
                      attributions:
                        type: array
                        items:
                          type: object
                          description: >-
                            An attribution: a dated record inside a revenue
                            traceability whose custom fields name who takes part
                            in its revenue.
                          properties:
                            id:
                              type: string
                              format: uuid
                              description: >-
                                The unique identifier of the attribution in our
                                system.
                            startDate:
                              type: string
                              format: date
                              description: The first day that the attribution covers.
                            endDate:
                              type: string
                              format: date
                              nullable: true
                              description: >-
                                The last day that the attribution covers. Null
                                when the attribution has no end.
                            customFields:
                              type: object
                              description: >-
                                The values of the custom fields of attributions
                                on the attribution, keyed by the key of each
                                custom field.
                              additionalProperties:
                                anyOf:
                                  - type: string
                                  - type: array
                                    items:
                                      type: string
                              default: {}
                              example:
                                customField1: value1
                                customField2:
                                  - value2
                                  - value3
                          required:
                            - id
                            - startDate
                            - endDate
                            - customFields
                          additionalProperties: false
                        description: The attributions of the record.
                    required:
                      - id
                      - productId
                      - startDate
                      - endDate
                      - customFields
                      - attributions
                    additionalProperties: false
                  description: A list of items.
              required:
                - items
              additionalProperties: false
        required: true
        description: >-
          The revenue traceabilities that replace those of the contract, each
          with its attributions.
      responses:
        '200':
          description: >-
            The revenue traceabilities of the contract after the replacement,
            each with its attributions.
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items:
                      type: object
                      description: >-
                        A revenue traceability: a dated record that tags the
                        revenue of a product that a contract bills with the
                        tenant's custom fields. Its attributions are dated
                        records inside it whose custom fields name who takes
                        part in that revenue.
                      properties:
                        id:
                          type: string
                          format: uuid
                          description: >-
                            The unique identifier of the revenue traceability in
                            our system.
                        contractId:
                          type: string
                          format: uuid
                          description: >-
                            The unique identifier of the contract that bills the
                            product.
                        productId:
                          type: string
                          format: uuid
                          description: >-
                            The unique identifier of the product whose revenue
                            the record tags.
                        startDate:
                          type: string
                          format: date
                          description: The first day that the record covers.
                        endDate:
                          type: string
                          format: date
                          nullable: true
                          description: >-
                            The last day that the record covers. Null when the
                            record has no end.
                        customFields:
                          type: object
                          description: >-
                            The values of the custom fields of revenue
                            traceabilities on the revenue traceability, keyed by
                            the key of each custom field.
                          additionalProperties:
                            anyOf:
                              - type: string
                              - type: array
                                items:
                                  type: string
                          default: {}
                          example:
                            customField1: value1
                            customField2:
                              - value2
                              - value3
                        attributions:
                          type: array
                          items:
                            type: object
                            description: >-
                              An attribution: a dated record inside a revenue
                              traceability whose custom fields name who takes
                              part in its revenue.
                            properties:
                              id:
                                type: string
                                format: uuid
                                description: >-
                                  The unique identifier of the attribution in
                                  our system.
                              startDate:
                                type: string
                                format: date
                                description: The first day that the attribution covers.
                              endDate:
                                type: string
                                format: date
                                nullable: true
                                description: >-
                                  The last day that the attribution covers. Null
                                  when the attribution has no end.
                              customFields:
                                type: object
                                description: >-
                                  The values of the custom fields of
                                  attributions on the attribution, keyed by the
                                  key of each custom field.
                                additionalProperties:
                                  anyOf:
                                    - type: string
                                    - type: array
                                      items:
                                        type: string
                                default: {}
                                example:
                                  customField1: value1
                                  customField2:
                                    - value2
                                    - value3
                            required:
                              - id
                              - startDate
                              - endDate
                              - customFields
                            additionalProperties: false
                          description: The attributions of the record.
                      required:
                        - id
                        - contractId
                        - productId
                        - startDate
                        - endDate
                        - customFields
                        - attributions
                      additionalProperties: false
                    description: A list of items.
                required:
                  - items
                additionalProperties: false
        '400':
          description: >-
            The request cannot succeed as sent.


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

            - `duplicate_revenue_traceability_id`: two items have the same `id`.

            - `duplicate_revenue_attribution_id`: two attributions of the same
            item have the same `id`.

            - `invalid_revenue_traceability_window`: the `endDate` of an item or
            of one of its attributions is before its `startDate`.

            - `product_not_on_contract`: an item names a `productId` that no
            revenue traceability of the contract has and that no plan charge of
            a version of a plan instance of the contract bills.

            - `invalid_custom_fields`: the `customFields` of an item or of an
            attribution leave out a required custom field of that kind of
            record, name a key that no custom field of that kind of record has,
            or give a custom field a value that it does not take.
          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
                      - duplicate_revenue_traceability_id
                      - duplicate_revenue_attribution_id
                      - invalid_revenue_traceability_window
                      - product_not_on_contract
                      - invalid_custom_fields
                  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: '''items'' is required'
                    code: json_schema_validation_error
                duplicate_revenue_traceability_id:
                  value:
                    message: >-
                      revenue traceability id appears more than once in the
                      payload: {id}
                    code: duplicate_revenue_traceability_id
                duplicate_revenue_attribution_id:
                  value:
                    message: >-
                      revenue attribution id appears more than once on the same
                      annotation: {id}
                    code: duplicate_revenue_attribution_id
                invalid_revenue_traceability_window:
                  value:
                    message: >-
                      revenue traceability window end date must not be before
                      start date
                    code: invalid_revenue_traceability_window
                product_not_on_contract:
                  value:
                    message: >-
                      revenue traceability can only cover products the contract
                      bills: {value}
                    code: product_not_on_contract
                invalid_custom_fields:
                  value:
                    message: 'Unknown custom field(s) for {entity}: {value}'
                    code: invalid_custom_fields
        '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
            `contractId`.
          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: contract not found
                    code: contract_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.