What is the CAF (folios) from Chile's SII and how to request it with an API
Short answer: a folio is the unique number of an electronic tax document, and the CAF (Código de Autorización de Folios, Folio Authorization Code) is the XML file with the range of folios the SII (Chile's tax authority) authorizes for a RUT (Chilean tax ID) and a document type. The SII has no API to request them; SharkPOS requests them for you using the business's digital certificate, without the Clave Tributaria (SII password), and you can also upload your own CAF files.
What is a folio and what is a CAF?
Every boleta (receipt), factura (invoice) or note carries a folio, a number that does not repeat for that document type and that RUT. The SII authorizes ranges of folios, for example 1 to 500 for boletas, and delivers them in a CAF: an XML file with the range, the RUT, the document type and the key used for stamping. When issuing, the document is stamped with that key: that is the timbre (TED) printed as a PDF417 code.
According to the SharkPOS documentation, boleta and guía (dispatch guide) CAFs do not expire, while factura, purchase invoice and note CAFs (33, 34, 46, 56, 61) expire after 6 months.
Why do folios run out?
Because every document consumes one and the range is finite. When the last one is used, issuing that type is blocked and the API responds 409 FOLIOS_EXHAUSTED until there is a new range. That is why the point is to request the next range before reaching zero.
How are folios requested with SharkPOS?
By hand, a person logs in to sii.cl with their certificate, opens Timbraje electrónico (electronic stamping), requests the numbering and downloads the CAF XML. SharkPOS does exactly that for the issuer, with its certificate.
- When onboarding completes, it requests folios for each configured type (39 by default; add 41, 33, 34, 56, 61 or 52 if you will issue them). They arrive in the background, normally in under a minute.
- When a type has 50 folios or fewer left (
threshold, configurable), it requests 5,000 (batch_size, configurable), capped at the maximum the SII authorizes for that RUT. - It downloads the CAF, validates that it matches the same RUT and type, stores its key encrypted and activates it.
- It notifies with the
caf.auto_requestedwebhook or, if it fails,caf.auto_request_failedwith the reason.
The certificate must belong to the legal representative or to a user authorized by the company at the SII with permission to obtain folios, and the RUT must be enabled to issue through SharkPOS.
To see the balance without consuming anything:
curl "https://sandbox.sharkpos.cl/api/v1/dte/caf/status/?document_type=39" \
-H "Authorization: Bearer $SHARKPOS_API_KEY"
It returns remaining, the ranges and an alert_level. To request folios right now, even if automatic requests are turned off:
curl -X POST https://sandbox.sharkpos.cl/api/v1/dte/caf/requests/ \
-H "Authorization: Bearer $SHARKPOS_API_KEY" \
-H "Content-Type: application/json" \
-d '{"document_type": 39, "quantity": 5000}'
It responds 202: it is asynchronous, and the result arrives by webhook or with GET /api/v1/dte/caf/requests/{id}/. quantity is optional. To configure the threshold and the batch, use PATCH /api/v1/dte/caf/auto-request/.
What do I do if I get FOLIOS_EXHAUSTED?
With automatic folios, while a request is in progress and no folios are left, issuing responds 409 with a message saying the folios are on their way. Retry in a few minutes with the same Idempotency-Key. If the SII rejects the request, the two most common causes are: the RUT is still enrolled in e-Boleta (how to unsubscribe) or the certificate holder is not authorized (how to authorize them). The error details are in FOLIOS_EXHAUSTED.
Can I upload my own CAF files?
Yes. The CAF files you upload keep working the same way, of any type (39, 41, 33, 34, 46, 52, 56, 61):
curl -X POST https://sandbox.sharkpos.cl/api/v1/dte/caf/ \
-H "Authorization: Bearer $SHARKPOS_API_KEY" \
-F caf=@FoliosSII_33.xml \
-F last_used=1050
The response is a 201 with folio_start, folio_end and next_folio. It can also be done from the dashboard, under Mis RUT (My RUTs), in the RUT, in Folios.
What happens to folios when switching providers?
Switching providers does not require certifying again with the SII, according to the documentation. What matters is not repeating folios:
- Stop issuing with the previous system and note the last folio used for each type.
- Upload each valid CAF with
last_usedequal to that last folio. Numbering continues from the next one. - Check that
next_foliois the one after the last you used. If you already issued with higher folios and that CAF will not be used, it comes backnull.
Never issue with two systems on the same CAF: each keeps its own counter and folios would repeat. If you prefer to start clean, let SharkPOS request new folios. The full steps are in the guide to switching provider (in Spanish).
Try it in the sandbox
In the sandbox the test certificate and folios are already loaded: request your key at api.sharkpos.cl/sandbox and query caf/status without consuming real folios. In production, CLP 5,990 a month per RUT, VAT included, with 20,000 documents a month.
Try it today in the sandbox
Get a sandbox API key: a test company with certificate and folios already loaded and a simulated SII. When you are ready, each RUT costs CLP 5,990 a month (VAT included) with 20,000 documents a month.