Start parsing/validating an uploaded import batch (dry-run)
const url = 'https://api.emite.cr/v1/documents/imports/example/start';const options = { method: 'POST', headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'}, body: '{"files":[{"filename":"factura-001.xml","key":"tenants/<id>/sandbox/imports/<batch>/0-factura-001.xml"}]}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://api.emite.cr/v1/documents/imports/example/start \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data '{ "files": [ { "filename": "factura-001.xml", "key": "tenants/<id>/sandbox/imports/<batch>/0-factura-001.xml" } ] }'Call it once every file was PUT to its uploadUrl, with the filename and key of each upload target. Each XML becomes one item and each ZIP is extracted in the background; parsing runs asynchronously, so the batch normally comes back processing — poll GET /v1/documents/imports/{id} until it is completed, partial or failed. This is a dry run: each item shows what would happen and nothing is written until the commit. 409 IMPORT_ALREADY_STARTED for a batch already started, 400 IMPORT_KEY_OUTSIDE_BATCH for a key of another batch.
Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Path Parameters
Section titled “Path Parameters”Request Bodyrequired
Section titled “Request Bodyrequired”object
The files that were uploaded, one entry per upload target. Each XML becomes one item of the batch; each ZIP adds one item per .xml entry once it is extracted.
object
The filename of the upload target, as the batch creation returned it. A .zip name is extracted in the background; any other is processed as one XML document.
Example
factura-001.xmlThe storage key of the upload target, as the batch creation returned it, once the file was PUT to its uploadUrl. A key outside this batch is 400 IMPORT_KEY_OUTSIDE_BATCH.
Example
tenants/<id>/sandbox/imports/<batch>/0-factura-001.xmlResponses
Section titled “Responses”object
Id of the batch.
Environment the batch belongs to — that of the session or API key that created it. Its documents are written there.
What processing the batch does: validate — a dry run, which parses and classifies each file without writing anything; commit — the files are persisted (after POST /v1/documents/imports/{id}/commit).
Where the batch is: pending — created, waiting for start; processing — files being processed in the background; completed — every file processed without failures; partial — processed, with at least one failed file; failed — processed, and every file failed.
Name of the ZIP uploaded with the batch; null when only XML files were.
XML files in the batch. It grows while a ZIP is being extracted, by one per .xml entry.
Files processed so far.
Files with status imported (saved or, in a dry run, saveable).
Files with status skipped.
Files with status failed.
When the batch was created.
When the batch finished processing; null while it has not.
One entry per XML file, oldest first. Present when reading, starting or committing one batch; absent from the list.
object
Id of the item.
Name of the XML file; for an entry of a ZIP, its name inside the archive.
Outcome of the file: pending — not processed yet; imported — saved (in a validate batch, it would be saved by the commit); skipped — left out without an error (a duplicate, a document of another company…, see resultCode); failed — it could not be processed (see resultCode and errorMessage).
What the XML is: document — an electronic document (invoice, ticket, note…); response — a message about one (Hacienda's MensajeHacienda or a MensajeReceptor); unknown — neither. Null until the file is processed.
Which side of the document the company is on: issued — it is the issuer (Emisor); received — it is the receiver (Receptor), a purchase. Null until it is known.
Hacienda document type (TipoDocumento) read from the XML: 01 invoice, 02 debit note, 03 credit note, 04 ticket, 05–07 receptor messages, 08 purchase invoice, 09 export invoice, 10 payment receipt. Null when not detected.
The 50-digit clave read from the XML; null when not detected.
Why the file ended as it did, a closed vocabulary:
IMPORTED— saved (or, in a dry run, would be).RESPONSE_PAIRED— a response matched to a document already in EmiteCR, whose status it updated.DUPLICATE_CLAVE— a document with that clave already exists in this environment (skipped).NOT_TENANT_DOCUMENT— the company is neither its issuer nor its receiver (skipped).RECEPTION_LIMIT_REACHED— the monthly cap of received documents was reached (skipped).RESPONSE_NO_MATCH— a response without a matching document (skipped).MENSAJE_RECEPTOR_SKIPPED— a MensajeReceptor with an unrecognized<Mensaje>(skipped).UNSUPPORTED_ROOT— an XML that is not a Hacienda document (failed).PARSE_ERROR— empty, unreadable or malformed (failed).INVALID_CLAVE— the clave is not 50 digits (failed).PERSIST_ERROR— it could not be saved (failed).
Null while pending.
Technical detail of a failure, in English; null otherwise.
Id of the invoice the file became (an issued document), or the existing invoice a response was paired with; null otherwise, and in a dry run.
Id of the received document the file became (a purchase), or the existing one a response was paired with; null otherwise, and in a dry run.
When the file was processed; null while pending.
Example
{ "environment": "sandbox", "mode": "validate", "status": "pending", "sourceFilename": "xml-junio.zip", "items": [ { "originalFilename": "factura-001.xml", "status": "pending", "kind": "document", "direction": "issued", "detectedDocType": "01", "resultCode": "IMPORTED" } ]}