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

# Schedule a RADIAN event on an accepted invoice

> Checks the input, that the invoice is accepted, that its buyer is the issuer (the DIAN test environment accepts events only then; a sandbox key may use a third-party buyer), and the RADIAN chain and timing rules; then reserves an event number, builds, signs and saves the event and queues its sending at the projected `not_before` (the previous send plus the DIAN registration pause). The DIAN answer is recorded on the invoice by the worker. Reading it back is `GET /v1/invoices/{invoice_id}/events`.

`031` needs `claim_concept`; `030`/`032` need `receiver_person`. Send an `Idempotency-Key` to retry safely: a retry with the same key and body returns this response without taking a second event number.



## OpenAPI

````yaml /openapi.json post /v1/invoices/{invoice_id}/events
openapi: 3.1.0
info:
  description: >
    Cufea issues Colombian electronic invoices and related documents through the
    DIAN.

    Every API key drives one stage: `cufea_sandbox_` keys Cufea's simulated DIAN
    (no

    certificate or DIAN credentials needed), `cufea_test_` keys the DIAN
    habilitación (test)

    environment and `cufea_prod_` keys the DIAN production environment, which
    opens per tenant

    only after the operator promotes it. A key sees only the documents of its
    own stage.


    **Cufea owns** the DIAN logic: XML generation, CUFE/CUDE, signing,
    submission, status

    tracking, numbering, credit/debit notes and RADIAN events. It keeps a
    minimal registry

    (numbering, event chain, state, signed XML and DIAN responses) and always
    returns the

    signed XML.


    Credit (91) and debit (92) notes reference an invoice the DIAN accepted;
    they carry their

    own CUDE and are numbered by the client's series.


    How a document reaches the DIAN depends on the stage. In the test stage,
    until the DIAN

    accepts the tenant's habilitacion test set, the worker sends every invoice
    and note with

    SendTestSetAsync to that set and polls GetStatusZip for the answer. The
    first GetStatusZip

    answer that says the set "se encuentra Aceptado" records the acceptance; the
    DIAN closes that

    document without validating it (state `closed`, never accepted), so create
    it again: from then

    on, and always in production, documents go with SendBillSync, whose answer
    is final.


    **You own** your business data (customers, products, accounting), your RUT,
    your

    numbering resolution and your DIAN habilitacion.


    Authenticate every request except `/v1/health` with `Authorization: Bearer
    <api key>`.

    Resellers provision their clients' tenants under `/v1/partner` with a
    partner key

    (`cufea_partner_`), which only those routes accept (see the `partner`
    section).

    Errors are `application/problem+json` (RFC 9457) and carry a `request_id`
    that matches

    the `X-Request-ID` response header; quote it when asking for support.


    Each API key (tenant or partner) has its own quota, 120 requests per minute
    by default, in a

    fixed window aligned to the minute. Every response of a route that takes a
    key carries

    `X-RateLimit-Limit`, `X-RateLimit-Remaining` and `X-RateLimit-Reset` (whole
    seconds until the

    window restarts); over the quota the answer is `429 rate_limited` with
    `Retry-After` in whole

    seconds. The edge also limits requests per client IP.


    Creating and sending documents accept an `Idempotency-Key` header: a retry
    with the same key

    and body returns the stored answer (with `Idempotent-Replayed: true`)
    instead of acting twice.

    Sending is asynchronous: it answers `202` and a worker talks to the DIAN;
    follow the outcome

    by reading the document back or by registering a webhook endpoint, whose
    deliveries are

    signed with `X-Cufea-Signature` (see the `webhooks` section).


    The guides, the error catalog and this reference live at
    https://docs.cufea.com. New here?

    Sign up in the developer console for a sandbox key and follow the quickstart

    (https://docs.cufea.com/quickstart): a first invoice, its status and a
    verified webhook in

    minutes.
  summary: 'DIAN electronic invoicing: sandbox, test and production stages'
  title: Cufea API
  version: 0.8.0
servers:
  - description: Cufea API
    url: https://api.cufea.com
security: []
tags:
  - description: Service liveness.
    name: system
  - description: >-
      The account behind the API key: its configuration, secrets (write-only)
      and API keys.
    name: tenant
  - description: >-
      Register HTTPS endpoints that receive signed event deliveries
      (`invoice.accepted`, `invoice.rejected`, `note.accepted`, `note.rejected`,
      `event.registered`, and the buyer email outcomes `invoice.delivered`,
      `invoice.delivery_failed`, `note.delivered`, `note.delivery_failed`). The
      signing secret is shown once, on create. The payload and the signature are
      described under the document's `webhooks` section.
    name: webhooks
  - description: >-
      Create signed sales invoices, send them to the DIAN (queued), follow their
      status and get their AttachedDocument. Creating and sending accept an
      `Idempotency-Key` header.
    name: invoices
  - description: >-
      Create signed credit (91) and debit (92) notes on an accepted invoice,
      send them to the DIAN (queued: SendTestSetAsync to the test set until the
      DIAN accepts it, then SendBillSync) and read them back. Creating and
      sending accept an `Idempotency-Key` header.
    name: notes
  - description: >-
      Find an invoice or note by the `reference` you gave on create, e.g. to
      learn for sure whether a create whose answer was lost created the
      document.
    name: documents
  - description: >-
      Schedule RADIAN events (030-034) on an accepted invoice, re-queue a saved
      one and read the event chain. Creating accepts an `Idempotency-Key`
      header.
    name: events
  - description: >-
      For resellers: provision each client company as a tenant of its own (its
      NIT, its certificate) on the client's written authorization, and manage
      that tenant's API keys. Authenticate with a partner key
      (`cufea_partner_`), which the operator issues; it creates no documents and
      reads no secrets.
    name: partner
paths:
  /v1/invoices/{invoice_id}/events:
    post:
      tags:
        - events
      summary: Schedule a RADIAN event on an accepted invoice
      description: >-
        Checks the input, that the invoice is accepted, that its buyer is the
        issuer (the DIAN test environment accepts events only then; a sandbox
        key may use a third-party buyer), and the RADIAN chain and timing rules;
        then reserves an event number, builds, signs and saves the event and
        queues its sending at the projected `not_before` (the previous send plus
        the DIAN registration pause). The DIAN answer is recorded on the invoice
        by the worker. Reading it back is `GET
        /v1/invoices/{invoice_id}/events`.


        `031` needs `claim_concept`; `030`/`032` need `receiver_person`. Send an
        `Idempotency-Key` to retry safely: a retry with the same key and body
        returns this response without taking a second event number.
      operationId: create_event_v1_invoices__invoice_id__events_post
      parameters:
        - description: Prefix and number, e.g. `SETP990000001`.
          in: path
          name: invoice_id
          required: true
          schema:
            description: Prefix and number, e.g. `SETP990000001`.
            title: Invoice Id
            type: string
        - description: >-
            Makes the call safe to retry. Same key and same request: the first
            response is replayed with `Idempotent-Replayed: true` and nothing is
            done again. Same key and another request: 422
            `idempotency_key_reused`. Same key while the first request still
            runs: 409 `idempotency_in_progress`. Keys belong to your account;
            they expire 24 hours after first use, after which the same key is
            usable again for a new request. A 5xx, 403, 404 or 409 answer is not
            stored, so the same key can be retried after it.
          in: header
          name: Idempotency-Key
          required: false
          schema:
            anyOf:
              - maxLength: 255
                minLength: 1
                type: string
              - type: 'null'
            description: >-
              Makes the call safe to retry. Same key and same request: the first
              response is replayed with `Idempotent-Replayed: true` and nothing
              is done again. Same key and another request: 422
              `idempotency_key_reused`. Same key while the first request still
              runs: 409 `idempotency_in_progress`. Keys belong to your account;
              they expire 24 hours after first use, after which the same key is
              usable again for a new request. A 5xx, 403, 404 or 409 answer is
              not stored, so the same key can be retried after it.
            title: Idempotency-Key
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EventCreate'
        required: true
      responses:
        '202':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EventScheduled'
          description: Successful Response
          headers:
            Idempotent-Replayed:
              description: >-
                `true` when this is the stored response of an earlier identical
                request.
              schema:
                enum:
                  - 'true'
                type: string
            X-RateLimit-Limit:
              $ref: '#/components/headers/X-RateLimit-Limit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/X-RateLimit-Remaining'
            X-RateLimit-Reset:
              $ref: '#/components/headers/X-RateLimit-Reset'
        '401':
          content:
            application/problem+json:
              example:
                code: unauthorized
                detail: Missing or invalid API key.
                request_id: 3668a7374b1e4314b2f932a5620da1f1
                status: 401
                title: Unauthorized
                type: urn:cufea:problem:unauthorized
              schema:
                $ref: '#/components/schemas/Problem'
          description: Missing or invalid API key.
        '403':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
          description: The tenant is suspended (`tenant_suspended`).
          headers:
            X-RateLimit-Limit:
              $ref: '#/components/headers/X-RateLimit-Limit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/X-RateLimit-Remaining'
            X-RateLimit-Reset:
              $ref: '#/components/headers/X-RateLimit-Reset'
        '404':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
          description: The invoice is not stored for this tenant (`document_not_found`).
          headers:
            X-RateLimit-Limit:
              $ref: '#/components/headers/X-RateLimit-Limit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/X-RateLimit-Remaining'
            X-RateLimit-Reset:
              $ref: '#/components/headers/X-RateLimit-Reset'
        '409':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
          description: >-
            The tenant is not configured (`tenant_not_configured`), the invoice
            is not accepted (`invoice_not_accepted`), its buyer is not the
            issuer (`event_needs_issuer_buyer`; a sandbox key may use a
            third-party buyer), the chain or timing rules refuse the event
            (`event_not_allowed`, with `next_step`), or an identical request
            with the same `Idempotency-Key` is still running
            (`idempotency_in_progress`).
          headers:
            X-RateLimit-Limit:
              $ref: '#/components/headers/X-RateLimit-Limit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/X-RateLimit-Remaining'
            X-RateLimit-Reset:
              $ref: '#/components/headers/X-RateLimit-Reset'
        '422':
          content:
            application/problem+json:
              example:
                code: validation_error
                detail: >-
                  The request is not valid; see `errors` for the offending
                  fields.
                errors:
                  - loc:
                      - body
                      - customer
                    msg: Field required
                  - loc:
                      - body
                      - lines
                    msg: List should have at least 1 item after validation, not 0
                request_id: 88272d6eb903438690d3193e3113270a
                status: 422
                title: Request validation failed
                type: urn:cufea:problem:validation_error
              schema:
                $ref: '#/components/schemas/ValidationProblem'
          description: >-
            The body is malformed (`validation_error`), breaks an event rule
            (`event_invalid`) or the `Idempotency-Key` was used for a different
            request (`idempotency_key_reused`).
          headers:
            X-RateLimit-Limit:
              $ref: '#/components/headers/X-RateLimit-Limit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/X-RateLimit-Remaining'
            X-RateLimit-Reset:
              $ref: '#/components/headers/X-RateLimit-Reset'
        '429':
          content:
            application/problem+json:
              example:
                code: rate_limited
                detail: >-
                  This API key made more than 120 requests in the current
                  window. Retry after 17 seconds.
                request_id: 5d1c0b6f2e8a4f0c9a7b3e2d1c0f9a8b
                status: 429
                title: Too Many Requests
                type: urn:cufea:problem:rate_limited
              schema:
                $ref: '#/components/schemas/Problem'
          description: >-
            This API key is over its quota for the current window
            (`rate_limited`). Wait `Retry-After` seconds; a create or send
            retried with its `Idempotency-Key` is safe.
          headers:
            Retry-After:
              $ref: '#/components/headers/Retry-After'
            X-RateLimit-Limit:
              $ref: '#/components/headers/X-RateLimit-Limit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/X-RateLimit-Remaining'
            X-RateLimit-Reset:
              $ref: '#/components/headers/X-RateLimit-Reset'
        '500':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
          description: >-
            The document store failed (`store_error`). If an event number had
            already been reserved it is lost (never reused); the server logs it.
          headers:
            X-RateLimit-Limit:
              $ref: '#/components/headers/X-RateLimit-Limit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/X-RateLimit-Remaining'
            X-RateLimit-Reset:
              $ref: '#/components/headers/X-RateLimit-Reset'
        '503':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
          description: >-
            The server has no event services (or the job queue, or idempotency
            keys) configured.
          headers:
            X-RateLimit-Limit:
              $ref: '#/components/headers/X-RateLimit-Limit'
            X-RateLimit-Remaining:
              $ref: '#/components/headers/X-RateLimit-Remaining'
            X-RateLimit-Reset:
              $ref: '#/components/headers/X-RateLimit-Reset'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    EventCreate:
      additionalProperties: false
      description: A RADIAN event (030-034) about an invoice the DIAN accepted.
      properties:
        claim_concept:
          anyOf:
            - $ref: '#/components/schemas/ClaimConcept'
            - type: 'null'
          description: Reason of a 031 claim (AAH10); 031 only.
        code:
          $ref: '#/components/schemas/EventCode'
          description: '`030` acuse, `031` reclamo, `032` recibo, `033`/`034`.'
        receiver_person:
          anyOf:
            - $ref: '#/components/schemas/ReceiverPersonIn'
            - type: 'null'
          description: Who received it (AAH11); 030 and 032 only.
      required:
        - code
      title: EventCreate
      type: object
    EventScheduled:
      description: The receipt of an event create or re-queue request.
      properties:
        code:
          $ref: '#/components/schemas/EventCode'
          description: '`030`...`034`.'
        event_id:
          description: The saved event id, e.g. `EV1`.
          title: Event Id
          type: string
        invoice_id:
          description: The invoice the event belongs to.
          title: Invoice Id
          type: string
        not_before:
          anyOf:
            - format: date-time
              type: string
            - type: 'null'
          description: >-
            Projected instant the worker may send it; null when it was not
            queued or already has an answer.
          title: Not Before
        send:
          description: >-
            `queued`: this call queued it. `pending`: one was already queued or
            running. `sent`: the DIAN already answered it. `not_queued`: the
            event is saved but the job queue failed; send it with `POST
            .../events/{event_id}/send`.
          enum:
            - queued
            - pending
            - sent
            - not_queued
          title: Send
          type: string
      required:
        - invoice_id
        - event_id
        - code
        - send
      title: EventScheduled
      type: object
    Problem:
      description: Error body (`application/problem+json`, RFC 9457).
      properties:
        code:
          description: Stable machine-readable error code.
          title: Code
          type: string
        detail:
          description: Explanation specific to this occurrence.
          title: Detail
          type: string
        dian:
          anyOf:
            - $ref: '#/components/schemas/DianDetail'
            - type: 'null'
          description: Present only when the DIAN rejected a document.
        request_id:
          description: Value of the `X-Request-ID` response header.
          title: Request Id
          type: string
        status:
          description: HTTP status code.
          title: Status
          type: integer
        title:
          description: Short, human-readable summary of the problem kind.
          title: Title
          type: string
        type:
          description: Stable URI identifying the problem kind.
          title: Type
          type: string
      required:
        - type
        - title
        - status
        - code
        - detail
        - request_id
      title: Problem
      type: object
    ValidationProblem:
      description: A 422 problem. `errors` is present when `code` is `validation_error`.
      properties:
        code:
          description: Stable machine-readable error code.
          title: Code
          type: string
        detail:
          description: Explanation specific to this occurrence.
          title: Detail
          type: string
        dian:
          anyOf:
            - $ref: '#/components/schemas/DianDetail'
            - type: 'null'
          default: null
          description: Present only when the DIAN rejected a document.
        errors:
          anyOf:
            - items:
                $ref: '#/components/schemas/FieldError'
              type: array
            - type: 'null'
          default: null
          description: The offending fields, for `validation_error` only.
          title: Errors
        request_id:
          description: Value of the `X-Request-ID` response header.
          title: Request Id
          type: string
        status:
          description: HTTP status code.
          title: Status
          type: integer
        title:
          description: Short, human-readable summary of the problem kind.
          title: Title
          type: string
        type:
          description: Stable URI identifying the problem kind.
          title: Type
          type: string
      required:
        - type
        - title
        - status
        - code
        - detail
        - request_id
      title: ValidationProblem
      type: object
    ClaimConcept:
      description: >-
        Reason of an 031 claim. Toolbox ``TB/13.3.12 Concepto de Reclamo
        @listID``.


        ``@listID`` carries the code and ``@name`` the meaning; AAH92 only
        notifies on a

        mismatch (anexo19.txt:15514-15522).
      enum:
        - '01'
        - '02'
        - '03'
        - '04'
      title: ClaimConcept
      type: string
    EventCode:
      description: >-
        RADIAN events of a sales invoice (``TB/13.3.1 Eventos de un Documento
        Electrónico``).


        The description of each code is the literal AAH04 requires in

        ``DocumentResponse/Response/cbc:Description`` (anexo19.txt:15426, 15566,
        15748, 15827;

        032 at 31565-31567).
      enum:
        - '030'
        - '031'
        - '032'
        - '033'
        - '034'
      title: EventCode
      type: string
    ReceiverPersonIn:
      additionalProperties: false
      description: 'Who received the invoice or the goods (AAH11-AAH19): 030 and 032 only.'
      properties:
        check_digit:
          anyOf:
            - maxLength: 1
              type: string
            - type: 'null'
          description: DV, required for a NIT (id type `31`).
          title: Check Digit
        family_name:
          description: Family name of the receiver.
          title: Family Name
          type: string
        first_name:
          description: First name of the receiver.
          title: First Name
          type: string
        id_number:
          description: Identification number of the receiver.
          title: Id Number
          type: string
        id_type:
          $ref: '#/components/schemas/IdentificationType'
          description: Identification type, e.g. `13`.
        job_title:
          anyOf:
            - type: string
            - type: 'null'
          description: Job title, if known.
          title: Job Title
        organization_department:
          anyOf:
            - type: string
            - type: 'null'
          description: Organization department, if known.
          title: Organization Department
      required:
        - id_type
        - id_number
        - first_name
        - family_name
      title: ReceiverPersonIn
      type: object
    DianDetail:
      description: A DIAN rejection rule and its text, relayed verbatim to the client.
      properties:
        rule:
          description: DIAN validation rule code, for example `FAD06`.
          title: Rule
          type: string
        text:
          description: Rule description as returned by the DIAN.
          title: Text
          type: string
      required:
        - rule
        - text
      title: DianDetail
      type: object
    FieldError:
      description: One offending field of a request that failed validation.
      properties:
        loc:
          description: Where the field is, e.g. `["body", "lines"]`.
          items:
            type: string
          title: Loc
          type: array
        msg:
          description: What is wrong with it. The submitted value is never echoed.
          title: Msg
          type: string
      required:
        - loc
        - msg
      title: FieldError
      type: object
    IdentificationType:
      description: Fiscal identification document types. Toolbox list TipoIdFiscal-2.1.gc.
      enum:
        - '11'
        - '12'
        - '13'
        - '21'
        - '22'
        - '31'
        - '41'
        - '42'
        - '50'
        - '91'
      title: IdentificationType
      type: string
  headers:
    X-RateLimit-Limit:
      description: >-
        Requests this API key may make in the current window (120 per minute by
        default).
      example: 120
      schema:
        minimum: 1
        type: integer
    X-RateLimit-Remaining:
      description: Requests this API key has left in the current window.
      example: 119
      schema:
        minimum: 0
        type: integer
    X-RateLimit-Reset:
      description: Whole seconds until the window restarts and the quota is full again.
      example: 17
      schema:
        minimum: 1
        type: integer
    Retry-After:
      description: >-
        Whole seconds to wait before the next request (RFC 9110
        `delay-seconds`); equals `X-RateLimit-Reset`.
      example: 17
      schema:
        minimum: 1
        type: integer
  securitySchemes:
    ApiKeyAuth:
      bearerFormat: API key
      description: 'Send your Cufea API key as `Authorization: Bearer <key>`.'
      scheme: bearer
      type: http

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.