> ## 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 dunning schedule

> Replaces the name and the dunning steps of a dunning schedule. When `isDefault` is true, the dunning schedule becomes the default one of the tenant, and when it is false, the dunning schedule stops being the default. Each dunning step with the id of one of its dunning steps changes that dunning step, each dunning step without an id adds a dunning step, and the update removes each dunning step that the body leaves out. The dunning runs of the dunning schedule then follow the changed dunning steps.

Requires the role `dunning:write`.



## OpenAPI

````yaml /api-reference/openapi.yaml put /v1/dunning-schedules/{id}
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/dunning-schedules/{id}:
    put:
      tags:
        - Dunning
      summary: Update dunning schedule
      description: >-
        Replaces the name and the dunning steps of a dunning schedule. When
        `isDefault` is true, the dunning schedule becomes the default one of the
        tenant, and when it is false, the dunning schedule stops being the
        default. Each dunning step with the id of one of its dunning steps
        changes that dunning step, each dunning step without an id adds a
        dunning step, and the update removes each dunning step that the body
        leaves out. The dunning runs of the dunning schedule then follow the
        changed dunning steps.


        Requires the role `dunning:write`.
      parameters:
        - schema:
            type: string
            format: uuid
          in: path
          name: id
          required: true
          description: The unique identifier of the dunning schedule in our system.
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  description: The name of the dunning schedule.
                  example: Régua padrão
                isDefault:
                  type: boolean
                  description: >-
                    Whether the dunning schedule is the default one of the
                    tenant, which a customer follows when its creation leaves
                    out the dunning schedule. A tenant has at most one default
                    dunning schedule, and an archived dunning schedule is never
                    the default.
                steps:
                  type: array
                  minItems: 1
                  items:
                    type: object
                    description: >-
                      A dunning step: one e-mail of a dunning schedule, sent on
                      the issue day, on the due date, a number of days before or
                      after the due date, or after the payment. A dunning step
                      goes out inside the `dispatchWindow` of the dunning
                      settings, so with `business_hours` a dunning step whose
                      day falls on a Saturday or a Sunday goes out at 09:00 of
                      the next Monday.
                    properties:
                      name:
                        type: string
                        minLength: 1
                        description: The name of the dunning step.
                        example: Lembrete de vencimento
                      anchor:
                        type: string
                        enum:
                          - issued
                          - on_due_date
                          - due_date
                          - on_payment_confirmation
                        description: >-
                          When the dunning step sends its e-mail: `issued` on
                          the issue day of the invoice, `on_due_date` on its due
                          date, `due_date` the number of days in `offsetDays`
                          from its due date, and `on_payment_confirmation` after
                          Aira records its payment.
                      offsetDays:
                        type:
                          - 'null'
                          - integer
                        description: >-
                          The number of days from the due date on which a
                          `due_date` step sends, after the due date when
                          positive and before it when negative. It is null for
                          every other anchor.
                        example: 5
                      channel:
                        type: string
                        enum:
                          - email
                        description: >-
                          The channel through which the dunning step reaches the
                          invoice recipients.
                      content:
                        type: object
                        description: >-
                          The e-mail that the dunning step sends. The subject,
                          the title and the body can hold variables in double
                          braces, such as `{{ invoiceNumber }}`, `{{ dueDate }}`
                          or `{{ paymentLink }}`, which Aira fills in for each
                          invoice.
                        properties:
                          subject:
                            type: string
                            minLength: 1
                            description: The subject of the e-mail.
                            example: Sua fatura {{ invoiceNumber }}
                          title:
                            type: string
                            minLength: 1
                            description: The title that the e-mail shows above its body.
                            example: Sua fatura está disponível!
                          body:
                            type: string
                            minLength: 1
                            description: The text of the e-mail.
                            example: >-
                              Olá {{ billingAccountBusinessName }}, sua fatura
                              vence em {{ dueDate }}.
                          attachments:
                            type: object
                            description: >-
                              The files that the e-mail of the dunning step
                              attaches. A dunning step can attach only the files
                              that the `attachmentOptions` of the dunning
                              settings list.
                            properties:
                              artifacts:
                                type: array
                                description: >-
                                  The invoice artifacts that the e-mail
                                  attaches.
                                items:
                                  type: object
                                  properties:
                                    type:
                                      anyOf:
                                        - enum:
                                            - default:invoice_pdf
                                        - type: string
                                          pattern: ^custom:.+$
                                      description: >-
                                        The type of the invoice artifact:
                                        `default:invoice_pdf` for the invoice
                                        PDF, or `custom:*` for an invoice
                                        artifact of the tenant.
                                  required:
                                    - type
                                  additionalProperties: false
                              paymentFiles:
                                type: boolean
                                description: >-
                                  Whether the e-mail attaches the files of the
                                  payment of the invoice: the boleto, the Pix
                                  file or both, as the payment method of its
                                  contract produces. A dunning step that sends
                                  after the payment cannot attach them.
                              fiscalDocumentFiles:
                                type: boolean
                                description: >-
                                  Whether the e-mail attaches the PDF and the
                                  XML of the fiscal document of the invoice.
                              invoiceAttachmentFiles:
                                type: boolean
                                description: >-
                                  Whether the e-mail attaches the invoice
                                  attachments that the tenant marked to go out
                                  with the invoice.
                            required:
                              - artifacts
                              - paymentFiles
                              - fiscalDocumentFiles
                              - invoiceAttachmentFiles
                            additionalProperties: false
                        required:
                          - subject
                          - title
                          - body
                          - attachments
                        additionalProperties: false
                      id:
                        type: string
                        format: uuid
                        description: >-
                          The id of a dunning step of this dunning schedule, to
                          keep and change that dunning step. Leave it out to add
                          a dunning step.
                    required:
                      - name
                      - anchor
                      - offsetDays
                      - channel
                      - content
                    additionalProperties: false
                  description: >-
                    All the dunning steps of the dunning schedule, at least one.
                    Each dunning step of the dunning schedule that the list
                    leaves out is removed.
              required:
                - name
                - isDefault
                - steps
              additionalProperties: false
        required: true
        description: The dunning schedule with all its dunning steps.
      responses:
        '200':
          description: >-
            A dunning schedule: the sequence of e-mails about an invoice, from
            its issue to after its due date, and after its payment. Each
            customer follows at most one.
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    format: uuid
                    description: >-
                      The unique identifier of the dunning schedule in our
                      system.
                  name:
                    type: string
                    minLength: 1
                    description: The name of the dunning schedule.
                    example: Régua padrão
                  isDefault:
                    type: boolean
                    description: >-
                      Whether the dunning schedule is the default one of the
                      tenant, which a customer follows when its creation leaves
                      out the dunning schedule. A tenant has at most one default
                      dunning schedule, and an archived dunning schedule is
                      never the default.
                  archivedAt:
                    type:
                      - 'null'
                      - string
                    format: date-time
                    description: >-
                      The timestamp when the dunning schedule was archived, or
                      null if not archived. An archived dunning schedule cannot
                      be changed or assigned to a customer.
                  steps:
                    type: array
                    items:
                      type: object
                      description: >-
                        A dunning step: one e-mail of a dunning schedule, sent
                        on the issue day, on the due date, a number of days
                        before or after the due date, or after the payment. A
                        dunning step goes out inside the `dispatchWindow` of the
                        dunning settings, so with `business_hours` a dunning
                        step whose day falls on a Saturday or a Sunday goes out
                        at 09:00 of the next Monday.
                      properties:
                        id:
                          type: string
                          format: uuid
                          description: >-
                            The unique identifier of the dunning step in our
                            system.
                        name:
                          type: string
                          minLength: 1
                          description: The name of the dunning step.
                          example: Lembrete de vencimento
                        anchor:
                          type: string
                          enum:
                            - issued
                            - on_due_date
                            - due_date
                            - on_payment_confirmation
                          description: >-
                            When the dunning step sends its e-mail: `issued` on
                            the issue day of the invoice, `on_due_date` on its
                            due date, `due_date` the number of days in
                            `offsetDays` from its due date, and
                            `on_payment_confirmation` after Aira records its
                            payment.
                        offsetDays:
                          type:
                            - 'null'
                            - integer
                          description: >-
                            The number of days from the due date on which a
                            `due_date` step sends, after the due date when
                            positive and before it when negative. It is null for
                            every other anchor.
                          example: 5
                        channel:
                          type: string
                          enum:
                            - email
                          description: >-
                            The channel through which the dunning step reaches
                            the invoice recipients.
                        content:
                          type: object
                          description: >-
                            The e-mail that the dunning step sends. The subject,
                            the title and the body can hold variables in double
                            braces, such as `{{ invoiceNumber }}`, `{{ dueDate
                            }}` or `{{ paymentLink }}`, which Aira fills in for
                            each invoice.
                          properties:
                            subject:
                              type: string
                              minLength: 1
                              description: The subject of the e-mail.
                              example: Sua fatura {{ invoiceNumber }}
                            title:
                              type: string
                              minLength: 1
                              description: The title that the e-mail shows above its body.
                              example: Sua fatura está disponível!
                            body:
                              type: string
                              minLength: 1
                              description: The text of the e-mail.
                              example: >-
                                Olá {{ billingAccountBusinessName }}, sua fatura
                                vence em {{ dueDate }}.
                            attachments:
                              type: object
                              description: >-
                                The files that the e-mail of the dunning step
                                attaches. A dunning step can attach only the
                                files that the `attachmentOptions` of the
                                dunning settings list.
                              properties:
                                artifacts:
                                  type: array
                                  description: >-
                                    The invoice artifacts that the e-mail
                                    attaches.
                                  items:
                                    type: object
                                    properties:
                                      type:
                                        anyOf:
                                          - enum:
                                              - default:invoice_pdf
                                          - type: string
                                            pattern: ^custom:.+$
                                        description: >-
                                          The type of the invoice artifact:
                                          `default:invoice_pdf` for the invoice
                                          PDF, or `custom:*` for an invoice
                                          artifact of the tenant.
                                    required:
                                      - type
                                    additionalProperties: false
                                paymentFiles:
                                  type: boolean
                                  description: >-
                                    Whether the e-mail attaches the files of the
                                    payment of the invoice: the boleto, the Pix
                                    file or both, as the payment method of its
                                    contract produces. A dunning step that sends
                                    after the payment cannot attach them.
                                fiscalDocumentFiles:
                                  type: boolean
                                  description: >-
                                    Whether the e-mail attaches the PDF and the
                                    XML of the fiscal document of the invoice.
                                invoiceAttachmentFiles:
                                  type: boolean
                                  description: >-
                                    Whether the e-mail attaches the invoice
                                    attachments that the tenant marked to go out
                                    with the invoice.
                              required:
                                - artifacts
                                - paymentFiles
                                - fiscalDocumentFiles
                                - invoiceAttachmentFiles
                              additionalProperties: false
                          required:
                            - subject
                            - title
                            - body
                            - attachments
                          additionalProperties: false
                      required:
                        - id
                        - name
                        - anchor
                        - offsetDays
                        - channel
                        - content
                      additionalProperties: false
                    description: >-
                      The dunning steps of the dunning schedule, ordered by when
                      they send: the issue day first, then by the days from the
                      due date, and the payment last.
                required:
                  - id
                  - name
                  - isDefault
                  - archivedAt
                  - steps
                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.

            - `dunning_step_invalid`: a `due_date` dunning step has no
            `offsetDays`, a dunning step of another anchor has one, a dunning
            step attaches a file that the `attachmentOptions` of the dunning
            settings do not list, an `on_payment_confirmation` dunning step
            attaches the files of the payment, or a dunning step has an `id`
            that is not the id of a dunning step of the dunning schedule.

            - `dunning_schedule_archived`: the dunning schedule 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:
                      - json_schema_validation_error
                      - dunning_step_invalid
                      - dunning_schedule_archived
                  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: '''name'' is required'
                    code: json_schema_validation_error
                dunning_step_invalid:
                  value:
                    message: >-
                      step "{name}" asks for an attachment the tenant setup does
                      not produce
                    code: dunning_step_invalid
                dunning_schedule_archived:
                  value:
                    message: cannot update an archived schedule
                    code: dunning_schedule_archived
        '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 dunning: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.


            - `dunning_schedule_not_found`: no dunning schedule of the tenant
            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:
                      - dunning_schedule_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:
                dunning_schedule_not_found:
                  value:
                    message: dunning schedule not found
                    code: dunning_schedule_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.