Skip to main content

POST /v1/invoices

Issues a signed e-CF and submits it to DGII asynchronously.

Request

curl -X POST https://sandbox.api.erply.pro/v1/invoices \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d @invoice.json

Required headers

HeaderNotes
AuthorizationBearer <jwt> obtained from /v1/auth/token.
Idempotency-KeyUUID v4. TTL 24 h.
Content-Typeapplication/json; charset=utf-8.

Body

The canonical body lives in tests/fixtures/quickstart_invoice_request.json and is validated against the InvoicePayload model on every commit (see tests/unit/test_quickstart_fixture.py):

{
"type": "31",
"encf": "E310000000001",
"client_request_id": "req-2026-05-01-001",
"company": { "rnc": "131000001", "name": "ERPly Pro Demo S.R.L." },
"customer": { "rnc": "131000002", "name": "Cliente Demo S.R.L." },
"lines": [
{
"line_number": 1,
"description": "Servicio de consultoria",
"quantity": "1",
"unit_price": "5000.00",
"subtotal": "5000.00"
}
],
"totals": { "subtotal": "5000.00", "tax": "900.00", "grand_total": "5900.00" }
}

Contract notes

  • tenantId does not go in the body. The handler derives it from the JWT claims (tenant_id, environment) via TenantContext.from_event. BUG-EP-03 fixed the drift between the published OpenAPI and the implementation: the field was never accepted by the Lambda body schema.
  • Decimals as strings. quantity, unit_price, subtotal, totals.* are accepted as strings to avoid client-side rounding errors; the server validates Σ lines[].subtotal == totals.subtotal ± 0.01 and totals.subtotal + totals.tax == totals.grand_total.
  • client_request_id (8–64 chars) is the body-level idempotency key; the Idempotency-Key header covers network retries. Both coexist — see errors §replay.
  • encf and type must agree. The 2nd/3rd characters of encf (E**...) must equal type.

Responses

HTTPMeaning
202 AcceptedAccepted, queued for DGII.
200 OKIdempotent replay.
{
"docId": "01HW9X4G…",
"trackId": "20260501-DGII-9988",
"status": "pending",
"_links": {
"self": "/v1/invoices/01HW9X4G…",
"status": "/v1/invoices/01HW9X4G…/status"
}
}

Possible errors

HTTPSlugCause
400malformed-jsonBody is not JSON.
400unsupported-ecf-typeType outside the catalog.
400validation-errorPydantic failed.
401unauthorisedInvalid token.
422mathematical-discrepancyTotals don't match.
422tenant-config-missingMissing RNC/PFX.
422dgii-rejected (+ DGII code)DGII rejection.
504dgii-unavailableDGII timeout.

See the full DGII error dictionary for the numeric codes.