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

# From test to production

> Certificate, DIAN test set and promotion to production with the API.

A tenant reaches the DIAN production stage with its own test key, the same steps the console
offers its owner. A reseller provisioning its clients uses each client's test key.

1. **Signing certificate.** `PUT /v1/tenant/certificate/{stage}` with
   `{"p12_base64": "<the .p12 in base64>", "password": "<its password>"}`. A test key writes
   `test` and, write-only, `production`; a sandbox key writes nothing (`403
   stage_not_allowed`). The bundle is opened in memory and stored as the stage's `cert_pem`
   and `cert_key`; neither the file nor its password is kept or returned. The answer is the
   certificate's public metadata (subject, `identifier`, serial number, validity,
   fingerprint). `nit_mismatch: true` is a **warning**: the subject does not carry the
   issuer's NIT, as with a legal representative's certificate. A bundle that cannot sign
   (wrong password, not PKCS#12, expired or not valid yet, a key that does not match, a key
   usage without digital signature and non-repudiation, a Cufea sandbox certificate,
   excessive key derivation iterations) answers `422 certificate_invalid` naming the problem; a body over
   96 KB answers `413 payload_too_large` before it is read. `GET
   /v1/tenant/certificate/{stage}` reads the key's own stage only.
2. **Test set.** Send the documents of the DIAN set from the test stage and follow them with
   `GET /v1/tenant/test-set`:

   * `status`: `not_configured` (no issuer or TestSetId), `not_started` (no test-stage
     document), `in_progress`, or `accepted` (the DIAN accepted the current TestSetId,
     with `accepted_at`).
   * `documents`: test-stage invoices, credit and debit notes counted by their latest DIAN
     outcome (`accepted`, `rejected`, `pending`, `failed`).
   * `last_dian_answer`: the latest DIAN status recorded on any of them, with its
     `status_code`, `status_description` and rule messages.

   There is no `rejected` status: Cufea recognises the DIAN's acceptance only, so a failed
   set stays `in_progress`; read the rejected counts and `last_dian_answer`. The counts are
   those of the test stage, not of one TestSetId: after the issuer gets a new TestSetId they
   still include the earlier set's documents (the acceptance itself follows the TestSetId).
   The DIAN sets how many documents a set needs; Cufea reports no required counts.
3. **Production preconditions.** Register the production software id in
   `PUT /v1/tenant/issuer` (`production_software_id`), add a production range and the
   production secrets with `?environment=production` (numbering range, `software_pin`,
   `technical_key`, and the production certificate of step 1). `GET /v1/tenant/promotion`
   lists what is still missing, one message per item; `?copy_from_test=true` counts what the
   test stage would fill.
4. **Promotion.** `POST /v1/tenant/promote` (test key only) opens the production stage, or
   answers `422 promotion_refused` with `missing`. With `{"copy_from_test": true}` the
   software id, PIN, certificate and key production lacks are copied from the test stage in
   the promotion's own transaction (never the technical key, which belongs to the production
   range). A second call answers `200` unchanged. The database re-checks every precondition,
   including that no other tenant is in production with the same NIT. The promotion issues
   no production key; the first one is the operator's.

There is no password confirmation over the API: the test key is the authority, so keep it
like a password. Every configuration write made with a key (issuer, numbering range, secret,
certificate, API key issue and revoke, promotion) is recorded in the tenant's audit log with
the key's id as the actor, never a secret value.


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