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

# Update contract recurring discount

> Replaces the custom fields of an active recurring discount of a contract. The invoices that are not locked carry the new values on the discounts that the recurring discount gives them.

Requires the role `contracts:write`.



## OpenAPI

````yaml /api-reference/openapi.yaml patch /v1/contracts/{id}/recurring-discounts/{contractRecurringDiscountId}
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}/recurring-discounts/{contractRecurringDiscountId}:
    patch:
      tags:
        - Contracts
      summary: Update contract recurring discount
      description: >-
        Replaces the custom fields of an active recurring discount of a
        contract. The invoices that are not locked carry the new values on the
        discounts that the recurring discount gives them.


        Requires the role `contracts:write`.
      parameters:
        - schema:
            type: string
            format: uuid
          in: path
          name: id
          required: true
          description: Unique identifier for the contract.
        - schema:
            type: string
            format: uuid
          in: path
          name: contractRecurringDiscountId
          required: true
          description: The unique identifier of the recurring discount in our system.
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                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
              required:
                - customFields
              additionalProperties: false
        required: true
        description: The custom fields that replace those of the recurring discount.
      responses:
        '200':
          description: >-
            A discount that a contract applies from a chosen billing cycle, for
            a number of billings or with no end. It is a fixed amount or a
            percentage on the invoice, a plan, one plan charge or the contract
            minimum.
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    format: uuid
                    description: >-
                      The unique identifier of the recurring discount in our
                      system.
                  planId:
                    type: string
                    format: uuid
                    nullable: true
                    description: >-
                      The unique identifier of the plan that the discount
                      applies to, for the plan and plan_charge target scopes.
                      Null for the invoice and contract_minimum_amount target
                      scopes.
                  planChargeId:
                    type: string
                    format: uuid
                    nullable: true
                    description: >-
                      The unique identifier of the plan charge that the discount
                      applies to, for the plan_charge target scope. Null for the
                      other target scopes.
                  targetScope:
                    type: string
                    enum:
                      - invoice
                      - plan
                      - plan_charge
                      - contract_minimum_amount
                    description: >-
                      What the discount applies to on each invoice: invoice (the
                      whole invoice), plan (the line items of the plan),
                      plan_charge (the line item of one plan charge of the
                      plan), or contract_minimum_amount (the line item that the
                      contract minimum adds).
                  method:
                    type: string
                    enum:
                      - fixed
                      - percentage
                    description: >-
                      How amount reads: fixed takes an amount of money off the
                      target, and percentage takes a percentage of the target
                      off it.
                  amount:
                    type: number
                    multipleOf: 1
                    minimum: 1
                    description: >-
                      The value of the discount, as a positive integer: cents
                      when method is fixed, and basis points when method is
                      percentage, where 1 basis point is 0.01% and 10000 is
                      100%.
                  description:
                    type: string
                    minLength: 1
                    description: The text of the discount as it appears on invoices.
                    example: Desconto de fidelidade
                  startDate:
                    type: string
                    format: date
                    description: >-
                      The start date of the billing cycle from which the
                      discount applies.
                  invoiceCount:
                    type: number
                    multipleOf: 1
                    minimum: 1
                    nullable: true
                    description: >-
                      How many billing acts that bill the target the discount
                      applies to, counted from startDate over the open invoices,
                      because an issued invoice keeps its discounts and spends
                      no count. The invoices that one billing act splits among
                      payment accounts spend one count together, so 12 counts on
                      a quarterly fee last 12 quarters. Null means that the
                      discount applies until it is deactivated.
                  distributionMode:
                    type: string
                    enum:
                      - proportional
                      - full
                    description: >-
                      How a fixed discount reaches the invoices that one billing
                      act splits among payment accounts: full takes the whole
                      amount off each invoice, and proportional splits the
                      amount among them in proportion to their totals. A
                      percentage discount always applies to each invoice.
                  isActive:
                    type: boolean
                    description: >-
                      Whether the discount applies to new billing cycles. A
                      deactivated discount stays on the contract for history.
                  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
                required:
                  - id
                  - planId
                  - planChargeId
                  - targetScope
                  - method
                  - amount
                  - description
                  - startDate
                  - invoiceCount
                  - distributionMode
                  - isActive
                  - customFields
                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.

            - `contract_recurring_discount_already_inactive`: the recurring
            discount is already inactive.

            - `invalid_custom_fields`: the custom fields leave out a required
            custom field of invoice discounts, name a key that no custom field
            of invoice discounts 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
                      - contract_recurring_discount_already_inactive
                      - 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: '''customFields'' is required'
                    code: json_schema_validation_error
                contract_recurring_discount_already_inactive:
                  value:
                    message: contract recurring discount is already inactive
                    code: contract_recurring_discount_already_inactive
                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 `id`.

            - `contract_recurring_discount_not_found`: no recurring discount of
            the contract has the `contractRecurringDiscountId`.
          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
                      - contract_recurring_discount_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
                contract_recurring_discount_not_found:
                  value:
                    message: contract recurring discount not found
                    code: contract_recurring_discount_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.