API Integration
Steps for Issuing a DTE
Below are the necessary steps to issue an Electronic Tax Document (DTE) through LibreDTE.
1. [POST] Issuing a Temporary DTE (Draft or Quotation)
This endpoint allows you to issue a temporary document in LibreDTE:
POST https://libredte.cl/api/dte/documentos/emitir?normalizar=1&formato=json&links=0&email=0
Parameter | Type | Description |
---|---|---|
normalizar |
int | 1 : Apply normalization.0 : Do not apply normalization. |
formato |
string | Format of the submitted data used to create the DTE:json : JSON format (default).xml : XML format.yaml : YAML format. |
links |
int | 1 : Include links associated with the temporary document.0 : Do not include links. |
email |
int | 1 : Send the document by email to the recipient..0 : Do not send the document by email. |
The body of the request must include the DTE or receipt content. For example, the following JSON represents the contents of an electronic receipt (boleta electrónica):
{
"Encabezado": {
"IdDoc": {
"TipoDTE": 39
},
"Emisor": {
"RUTEmisor": "76123456-9"
},
"Receptor": {
"RUTRecep": "11222333-4",
"RznSocRecep": "Juan Pérez",
"GiroRecep": "Informática",
"DirRecep": "Domicilio de Juan 123",
"CmnaRecep": "Santa Cruz"
}
},
"Detalle": [
{
"NmbItem": "Conectores RJ45",
"QtyItem": 450,
"PrcItem": 70
}
]
}
In this example, field normalization is applied, so it is not necessary to include total amounts or VAT, as these will be calculated automatically.
Adding Extra Data to the DTE
LibreDTE allows the inclusion of extra data, which is mainly used to enhance the content shown in the generated PDF files. This functionality is useful in various scenarios, such as:
- Adding invoice-specific fields to other document types, like receipts.
Example: the TermPagoGlosa field to indicate payment terms. - Including custom business information not covered by SII but relevant to the client or business.
Example: a graph showing a customer’s water consumption history.
To include this extra data, add a LibreDTE index inside the DTE data structure. This index must contain an extra
array with the custom fields, using a structure like the following:
{
"LibreDTE": {
"extra": {
"dte": {
"Encabezado": {
"IdDoc": {
"TermPagoGlosa": "OBSERVACIONES"
}
}
},
"historial": {
"titulo": "Consumo de Agua Potable",
"datos": {
"Feb": 12,
"Mar": 11,
"Abr": 12,
"May": 10.5,
"Jun": 4,
"Jul": 5
}
},
"servicios_basicos": {
"consumos": {
"unidad": "M3",
"lectura_actual": 9,
"lectura_anterior": 5.9,
"consumo_calculado": 3.1,
"consumo_facturado": 3,
"limite_sobreconsumo": 40
}
}
}
}
}
2. [POST] Generate Real DTE from Temporary DTE
This endpoint allows you to generate a real DTE based on a previously created temporary document.
https://libredte.cl/api/dte/documentos/generar?getXML=0&links=0&email=0&retry=10&gzip=0
Parámetro | Tipo | Descripción |
---|---|---|
getXML |
int | 1 : Includes the XML in the response.0 : Does not include the XML. |
links |
int | 1 : Includes links associated with the DTE.0 : Does not include links. |
email |
int | 1 : Sends the document by email to the recipient.0 : Does not send the document by email. |
The body of the request must contain the data returned from the previous step (temporary DTE issuance):
{
"emisor": 76123456,
"receptor": 66666666,
"dte": 39,
"codigo": "557ccc1706a77a212354d0f1734fd0adc"
}
3. [GET] Generate PDF of an Issued DTE
This endpoint allows you to generate a PDF version of a DTE issued in LibreDTE.
https://libredte.cl/api/dte/dte_emitidos/pdf/:dte/:folio/:emisor?formato=general&papelContinuo=0
Key Parameters
- formato: Defines the PDF layout:
- estandar: basic layout.
- general: includes images and an additional chart.
- servicios_basicos: layout for utility billing documents.
- papelContinuo: Defines the paper format:
- 0: letter size.
- 80: continuous paper (80mm).
- 57: continuous paper (57mm).
The response will return the binary content of the generated PDF.
More details are available in the official developer documentation.
Need Additional Help?
If you need help with the points mentioned in the document, please open a support ticket I need help