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

# Add a webhook endpoint

> Registers an HTTPS endpoint for the given event types (an empty list means every type) and returns its signing secret. **The secret is shown once**: only an encrypted copy is kept, so it cannot be retrieved again. Store it now.

Every delivery is a POST signed with `X-Cufea-Signature: t=<unix seconds>,v1=<hex>`, the HMAC-SHA256 of `{t}.{raw body}` keyed with this secret; reject a `t` more than 300 seconds from your clock. Only `https` URLs on public hosts are delivered to; see the `webhooks` section for the payload and retries.

Send an `Idempotency-Key` to retry safely: a retry with the same key and body registers nothing new. Because the secret is shown once, that retry does not repeat it: it answers 409 `idempotency_secret_withheld` naming the endpoint the first request created (`endpoint_id`). If that first answer was lost, delete the endpoint and create a new one.



## OpenAPI

````yaml /openapi.json post /v1/tenant/webhooks
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/tenant/webhooks:
    post:
      tags:
        - webhooks
      summary: Add a webhook endpoint
      description: >-
        Registers an HTTPS endpoint for the given event types (an empty list
        means every type) and returns its signing secret. **The secret is shown
        once**: only an encrypted copy is kept, so it cannot be retrieved again.
        Store it now.


        Every delivery is a POST signed with `X-Cufea-Signature: t=<unix
        seconds>,v1=<hex>`, the HMAC-SHA256 of `{t}.{raw body}` keyed with this
        secret; reject a `t` more than 300 seconds from your clock. Only `https`
        URLs on public hosts are delivered to; see the `webhooks` section for
        the payload and retries.


        Send an `Idempotency-Key` to retry safely: a retry with the same key and
        body registers nothing new. Because the secret is shown once, that retry
        does not repeat it: it answers 409 `idempotency_secret_withheld` naming
        the endpoint the first request created (`endpoint_id`). If that first
        answer was lost, delete the endpoint and create a new one.
      operationId: create_webhook_v1_tenant_webhooks_post
      parameters:
        - 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:
            examples:
              every_event:
                summary: Every event type to one HTTPS endpoint
                value:
                  event_types: []
                  url: https://hooks.example.com/cufea
            schema:
              $ref: '#/components/schemas/WebhookIn'
        required: true
      responses:
        '201':
          content:
            application/json:
              example:
                active: true
                created_at: '2026-11-15T01:37:52.317407Z'
                event_types: []
                id: 1526a4ef-0812-424c-b413-cc645415a617
                secret: '<shown once: store it now>'
                url: https://hooks.example.com/cufea
              schema:
                $ref: '#/components/schemas/WebhookCreated'
          description: Successful Response
          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'
        '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.
        '409':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
          description: >-
            The `Idempotency-Key` request is still running
            (`idempotency_in_progress`), or it already created the endpoint
            `endpoint_id` and its secret is not shown again
            (`idempotency_secret_withheld`, with `Idempotent-Replayed: true`).
          headers:
            Idempotent-Replayed:
              description: >-
                `true` on `idempotency_secret_withheld`: the answer 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'
        '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: >-
            Malformed (`validation_error`), breaking a webhook rule
            (`webhook_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'
        '503':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
          description: The server has no tenant services 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:
    WebhookIn:
      additionalProperties: false
      description: >-
        A webhook endpoint to register. Its signing secret is generated by the
        server.
      properties:
        event_types:
          description: Event types to deliver; an empty list means every type.
          items:
            type: string
          title: Event Types
          type: array
        url:
          description: HTTPS endpoint that receives the event deliveries.
          examples:
            - https://hooks.example.com/cufea
          title: Url
          type: string
      required:
        - url
      title: WebhookIn
      type: object
    WebhookCreated:
      properties:
        active:
          title: Active
          type: boolean
        created_at:
          format: date-time
          title: Created At
          type: string
        event_types:
          items:
            type: string
          title: Event Types
          type: array
        id:
          format: uuid
          title: Id
          type: string
        secret:
          description: 'Signing secret. Shown ONCE, here: it cannot be retrieved again.'
          title: Secret
          type: string
        url:
          description: HTTPS endpoint that receives the deliveries.
          title: Url
          type: string
      required:
        - id
        - url
        - event_types
        - active
        - created_at
        - secret
      title: WebhookCreated
      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
    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
  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.