API conventions
Conventions that hold across every endpoint. Learn them once.
Response shape
Section titled “Response shape”- Success returns the resource directly — no wrapper. Lists return a paged envelope (below).
- Error returns a structured envelope:
{ "error": { "code": "…", "messageKey": "errors.…", "message": "…", "params": {}, "details": {} }, "requestId": "…", "timestamp": "…", "path": "…"}Branch on error.code. params and details appear only when the error has
them. The main codes, by area: Error codes.
Request bodies
Section titled “Request bodies”Bodies are validated strictly: a field the endpoint doesn’t define is
rejected, not ignored (400 VALIDATION_ERROR, naming it in
details.fields). Send exactly the documented fields.
Pagination
Section titled “Pagination”List endpoints accept page (1-indexed) and pageSize, and return:
{ "items": [ … ], "total": 128, "page": 1, "pageSize": 25 }pageSize is capped server-side (commonly 100). Compute total pages as
ceil(total / pageSize).
Filtering & sorting
Section titled “Filtering & sorting”Filters are query params specific to each list (e.g. GET /v1/invoices accepts
status, docType, q, fechaEmisionFrom, fechaEmisionTo, from, to,
externalReference, sort, order). On invoices, fechaEmisionFrom /
fechaEmisionTo (and sort=fechaEmision) work on the date each document was
issued — the one its XML declares, its PDF prints and the reports count by —
while from / to bound when the record was created (a draft can be issued
days later; an imported XML is created the day it is imported). Use the
issue-date range for any fiscal period.
Multi-value filters repeat the key (?status=accepted&status=rejected). Sort
keys are stable and part of the contract — see each endpoint in the
API reference.
List exports
Section titled “List exports”The three human-facing lists can be downloaded as a spreadsheet:
GET /v1/invoices/export # scope: invoices:exportGET /v1/drafts/export # scope: invoices:export (cross-environment)GET /v1/proformas/export # scope: proformas:read- They accept the same filters as their list endpoint and run the same query, so the file always holds exactly what the list would have returned.
format=xlsx(default) orformat=csv. CSV carries a UTF-8 BOM so Excel reads the accents.page/pageSizeare ignored — an export covers the whole filtered set.- The result is capped (25,000 rows). When the cap clips it, the response carries
X-Export-Truncated: trueandX-Export-Row-Count: <n>— surface that to the user and narrow the range, or you are handing them a file that looks complete and is not. - Monetary columns include a CRC equivalent computed from the exchange rate
snapshotted on each document. A non-CRC document with no stored rate leaves
that cell empty rather than converting at
1. - Every export is recorded in the audit log (
invoice.exported/proforma.exported) with the filters it ran under.
Dates & times
Section titled “Dates & times”- All timestamps are ISO 8601. Responses are UTC (
…Z). - Fiscal dates that must reflect Costa Rica local time (the
clavedate segment,<FechaEmision>) are computed inAmerica/Costa_Rica. When you send afechaEmision, use an explicit-06:00offset.
Money & decimals
Section titled “Money & decimals”- Amounts are plain decimal numbers (not minor units) with up to 5 decimal places, the most the XSD’s money type allows on prices and totals (18 digits in all).
- Do monetary math with exact decimals, never binary floats: the server recomputes every line you send and refuses a difference over ±0.005 (see Create an invoice). In JavaScript, use a decimal library such as decimal.js.
Idempotency
Section titled “Idempotency”POST /v1/invoices (and creating a customer or an item) honors an
Idempotency-Key header for 24 hours; invoices also take the permanent
externalReference field. See
Idempotency & retries.
Rate limits
Section titled “Rate limits”API keys have no fixed request quota today. A few endpoints do limit how often
they are called — signing in, the partner control plane (30 requests per minute
per partner), billing changes, re-verifying Hacienda credentials (once a
minute), the XML backup download (two at a time per company). They answer
429, with the wait in a Retry-After header (seconds) or in
params.retryAfterSeconds when they know it: honor it, then retry. Treat any
429 as backpressure, and don’t poll faster than you need — every 30 seconds
is plenty for a document’s status.
Authentication
Section titled “Authentication”One credential per request: x-api-key (data plane), Authorization: Bearer
(JWT), or x-partner-key (partner). Each endpoint also requires
scopes. See
Authentication.
Versioning
Section titled “Versioning”The API is served under /v1. The surface grows additively; breaking changes
would ship under a new version prefix.