How to navigate between the endpoints
The four endpoints form one flow. Generation is asynchronous, so you never get the
documents back from the request that asks for them: you start a process, follow it, and
then read the documents it produced.
1- Create Fiscal Documents process which returns and id to be used on step 2.
2- Get Fiscal Document Process result status and results[].fiscal_document_ids to be used on step 3
4- [Optional] Get the Fiscal Document transactions
Step by step
- Generate. Call
POST /documents/fiscal-documentswith a period
(start_date+end_date) or a list oftransactions. The response is201with
{ "id": "..." }: the id of the process, not of a document. Sendexternal_idif you
want to look the process up later with your own reference. - Follow the process. Call
GET /documents/fiscal-documents/{id}with that id until
statusiscompletedorfailed. Each entry inresultsis one owner/counterpart pair
with its ownstatus(pending,success,failed,skipped), so a process can be
completedand still contain failed pairs. Readerroron those. A process with
nothing to generate is created alreadycompletedwith an emptyresults. - Read the documents. For every
successresult, take the ids infiscal_document_ids
and callGET /fiscal-documents/{id}. The response has a signed URL to download the
file (signedUrlorfiles[].file_url, depending on the type). Signed URLs expire, so
fetch the document again when you need a fresh link instead of storing the URL. - Drill into transactions (optional). Call
GET /fiscal-documents/{id}/transactions
with the document id to see which transactions it covers. It is paginated (page,
limit, up to 100), so use it for documents with many transactions.
Moving between documents
A document can point to others. Take an id
from relatedDocuments[].id and call GET /fiscal-documents/{id} again to follow the
link. Each related document is a full document of its own, with its own file and status.
I have X, I want Y
| I have | I want | Call |
|---|---|---|
| a period or a list of transactions | generated documents | POST /documents/fiscal-documents, then the process |
| the process id from the POST | its status and the document ids | GET /documents/fiscal-documents/{id} |
my own external_id for a process | its status and the document ids | GET /documents/fiscal-documents/{external_id}?use_external_id=true (returns an array) |
| a document id | the file and its metadata | GET /fiscal-documents/{id} |
my own external_id for a document | the file and its metadata | GET /fiscal-documents/{external_id}?use_external_id=true (returns an array) |
| a document id | the transactions behind it | GET /fiscal-documents/{id}/transactions |
| a document id | its linked documents | relatedDocuments[].id in the document, then GET /fiscal-documents/{id} |
The external_id you send when generating is stored on the process and on every document
it creates, which is why both "by external id" lookups return arrays: one reference can
match several processes or documents.
