---
title: "API Integration"
description: "How to integrate your own software with the LibreDTE API and start invoicing."
type: "academy"
category: "course"
tags: [api, english]
authors: [LibreDTE]
date: "2026-08-25"
last_update: "2026-08-25"
time_minutes: 10
draft: false
unlisted: false
image: "https://www.libredte.cl/img/content/academy/integracion-con-la-api/academy-integracion-api.jpg"
url: "https://www.stage.libredte.cl/academy/integration"
---

# API Integration




---

## Integration Guide for the Issuance of Electronic Tax Documents (DTE)



---

### Integration Guide for the Issuance of Electronic Tax Documents (DTE)

Integration Guide for the Issuance of Electronic Tax Documents (DTE)
# LibreDTE Web Services

# Integration Guide for the Issuance of Electronic Tax Documents (DTE)
## LibreDTE Web Services

[LibreDTE](https://www.libredte.cl) offers a web platform primarily focused on Electronic Invoicing. It provides a web application designed to generate electronic tax documents, known in Chile as &quot;Documentros Tributarios Electrónicos&quot; or &quot;DTE&quot;.

Throught its Web Services, LibreDTE enables external systems to integrate with its platform and issue DTEs directly from third-party software.

The complete official documentation is available at [libredte.cl/doc](https://libredte.cl/doc).

## Authentication via Hash

LibreDTE&#039;s Web Services use HTTP Basic authentication based on a **32-character hash**, which you can obtain from your user profile on the platform.

### Authentication Options

#### 1. Using the API HASH

The hash is available in the [API hash](https://libredte.cl/usuarios/perfil#datos:hashField) field of your user profile.

The following image shows the corresponding field:

![API Hash Field in LibreDTE](https://www.libredte.cl/img/content/academy/integracion-con-la-api/guia-de-integracion-para-emision-de-dte/api_hash_field.jpg){.w-75 .mx-auto}

To authenticate requests, this hash must be sent using **HTTP Basic Auth**, where the **username is the letter &quot;X&quot;** and the **password is your user&#039;s hash**.

If your user hash is **&quot;hash123&quot;** (real values are 32 characters long), then your API credentials must be Base64-encoded as follows:

```PHP
// Example usage in PHP.
$hash = &#039;hash123&#039;;
$credentials = base64_encode(&#039;X:&#039; . $hash);
$headers = [&#039;Authorization&#039; =&gt; &#039;Basic &#039; . $credentials];
```

The resulting header will look like this:

```http
Authorization: Basic WDpoYXNoMTIz
```

#### 2. Using the API Key

Alternatively, you can use the **Base64-encoded value** available directly in the [API KEY](https://libredte.cl/usuarios/perfil#datos:api_keyField) field of your profile.

The following image shows the corresponding field:

![Campo API Key en LibreDTE](https://www.libredte.cl/img/content/academy/integracion-con-la-api/guia-de-integracion-para-emision-de-dte/api_key_field.jpg){.w-75 .mx-auto}

This API key can be used directly in HTTP header:

```http
Authorization: Basic APIKEY
```


    
---

### Requirements for DTE Issuance Testing

Requirements for DTE Issuance Testing

# Requirements for DTE Issuance Testing

To carry out integration and electronic tax document (DTE) issuance tests, the following requirements must be met:

1. **Have a user account and register a company in LibreDTE.**
    - You can register and request access to the **Servicio Plus trial** through the following link: [https://www.libredte.cl/trial](https://www.libredte.cl/trial).
    &lt;br&gt;
    The trial period lasts **10 days** from the moment of registration.
2. **Upload the digital signature (Firma Electrónica Simple) of the legal representative.**
    - This signature is required to issue valid documents. You can upload it here: [https://libredte.cl/dte/admin/firma_electronicas](https://libredte.cl/dte/admin/firma_electronicas)
3. **Configure the folios (CAF) in the system.**
    - You must create the folio definitions and upload the CAF files authorized by the SII via the following link: [https://libredte.cl/dte/admin/dte_folios](https://libredte.cl/dte/admin/dte_folios)


    
---

### General Integration Flow

# General Integration Flow

## General Integration Flow

The process for issuing a DTE (Electronic Tax Document) consists of the following steps:

1. **Data Preparation** – Structuring the document’s information.
2. **Consuming Web Services** - Communicating with the LibreDTE API.
3. **Replicating the Basic Issuance Flow** - Executing the standard flow to issue a DTE using LibreDTE services.

### 1. Preparing DTE Data

You must structure the data that will be used to create the DTE. You can refer to example files covering the most common use cases in the following repository: [Example YAML Files](https://github.com/LibreDTE/libredte-lib-core/tree/master/tests/fixtures/yaml/documentos_ok).

Other scenarios should be constructed using the official documentation provided by the SII (Chilean Internal Revenue Service).

### 2. Consuming the Web Services

You have several options to interact with LibreDTE’s Web Services:

- Use the official SDKs provided by LibreDTE for your programming language. You can find them here: [LibreDTE Client Repositories](https://github.com/LibreDTE?q=Cliente).

- Develop your own client (SDK) to consume the services directly from your application.

- Use an HTTP library appropriate for your language to handle Web Services interactions (e.g., Guzzle HTTP for PHP or Requests for Python).

### 3. Replicating the Basic Issuance Flow

The minimum steps required to issue a DTE are:

1. Issue a temporary DTE
2. Generate a real DTE from the temporary version.
3. Check the status of the DTE submitted to the SII.
4. Retrieve the PDF of the finalized DTE.

&gt; [!NOTE] Note
&gt;
&gt;There are additional optional steps such as emailing documents or listing issued DTEs.
These are not mandatory and are not covered here. If you wish to perform these actions, please refer to the full documentation: [Web Service Documentation](https://www.libredte.cl/docs/api)

To issue a DTE and obtain its corresponding PDF, your code must perform the API calls illustrated in the following sequence diagram:

![LibreDTE Sequence Diagram](https://www.libredte.cl/img/content/academy/integracion-con-la-api/guia-de-integracion-para-emision-de-dte/diagrama_secuencial_libredte.jpg &quot;Diagrama de Secuencia para la Emisión de un DTE&quot;){.w-50 .mx-auto}

### DTE Normalization

LibreDTE includes a **DTE normalization process**, which helps reduce the amount of information required when building a DTE. For instance, the VAT amount on an invoice is calculated automatically based on the net amount and VAT rate, so if these values are not explicitly provided in the request, LibreDTE will compute them.

The normalization process performs the following actions:

- Adds missing discount/charge numbers and references.
- Normalizes the line item details: item numbers and item-level discounts.
- Applies global discounts or surcharges, calculating the respective amounts.
- Applies additional taxes or withholdings.
- Calculates VAT and/or total amounts.

### Request Format


The JSON object structure used to submit a DTE (Electronic Tax Document) follows the same fields, data types, and constraints as the corresponding DTE XML format. The full specification of the available fields in the XML can be found in the official documentation provided by the Chilean IRS (SII) at the following links:

- Electronic Tax Documents (excluding receipts/boletas):
    - DTE format description: [Electronic Tax Documents Format](https://www.sii.cl/factura_electronica/factura_mercado/formato_dte_202602.pdf).
    - DTE XML diagram: [DTE Diagram](https://www.sii.cl/factura_electronica/factura_mercado/diagrama_dte.zip)
- Electronic Receipts (Boletas):
    - Receipt format description: [Electronic Receipts Format](https://www.sii.cl/factura_electronica/factura_mercado/boletas_elec_0720_3.pdf)
    - Receipt XML diagram: [Receipt Diagram](https://www.sii.cl/factura_electronica/factura_mercado/diag_boleta_0920.zip)

In addition to **JSON**, other formats can be used to submit DTE data: **XML** and **YAML**. These formats must follow the same structural rules as JSON, adapted to their respective syntax.

If the submitted format is not JSON, the content must be sent encoded in **Base64**.

All examples in this documentation use JSON, which is the **default and recommended format** for integrating with LibreDTE’s Web Services.

If you have any questions or need assistance regarding the supported formats, please open a support ticket at: [Technical Support Request](https://www.libredte.cl/help?topic=technical).


    
---

### Steps for Issuing a DTE

Steps for Issuing a DTE

# 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:

```http
POST https://libredte.cl/api/dte/documentos/emitir?normalizar=1&amp;formato=json&amp;links=0&amp;email=0
```

| Parameter    | Type      | Description |
|--------------|-----------|-------------|
| `normalizar` | int       | `1`: Apply normalization.&lt;br&gt;`0`: Do not apply normalization. |
| `formato`    | string    | Format of the submitted data used to create the DTE:&lt;br&gt;`json`: JSON format (default).&lt;br&gt;`xml`: XML format.&lt;br&gt;`yaml`: YAML format. |
| `links`      | int       | `1`: Include links associated with the temporary document.&lt;br&gt;`0`: Do not include links. |
| `email`      | int       | `1`: Send the document by email to the recipient..&lt;br&gt;`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):

```json
{
    &quot;Encabezado&quot;: {
        &quot;IdDoc&quot;: {
            &quot;TipoDTE&quot;: 39
        },
        &quot;Emisor&quot;: {
            &quot;RUTEmisor&quot;: &quot;76123456-9&quot;
        },
        &quot;Receptor&quot;: {
            &quot;RUTRecep&quot;: &quot;11222333-4&quot;,
            &quot;RznSocRecep&quot;: &quot;Juan Pérez&quot;,
            &quot;GiroRecep&quot;: &quot;Informática&quot;,
            &quot;DirRecep&quot;: &quot;Domicilio de Juan 123&quot;,
            &quot;CmnaRecep&quot;: &quot;Santa Cruz&quot;
        }
    },
    &quot;Detalle&quot;: [
        {
            &quot;NmbItem&quot;: &quot;Conectores RJ45&quot;,
            &quot;QtyItem&quot;: 450,
            &quot;PrcItem&quot;: 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.&lt;br&gt; *Example*: the **TermPagoGlosa**  field to indicate payment terms.
- **Including custom business information not covered by SII but relevant to the client or business.**&lt;br&gt; *Example*: a graph showing a customer&#039;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:

```json
{
    &quot;LibreDTE&quot;: {
        &quot;extra&quot;: {
            &quot;dte&quot;: {
                &quot;Encabezado&quot;: {
                    &quot;IdDoc&quot;: {
                        &quot;TermPagoGlosa&quot;: &quot;OBSERVACIONES&quot;
                    }
                }
            },
            &quot;historial&quot;: {
                &quot;titulo&quot;: &quot;Consumo de Agua Potable&quot;,
                &quot;datos&quot;: {
                    &quot;Feb&quot;: 12,
                    &quot;Mar&quot;: 11,
                    &quot;Abr&quot;: 12,
                    &quot;May&quot;: 10.5,
                    &quot;Jun&quot;: 4,
                    &quot;Jul&quot;: 5
                }
            },
            &quot;servicios_basicos&quot;: {
                &quot;consumos&quot;: {
                    &quot;unidad&quot;: &quot;M3&quot;,
                    &quot;lectura_actual&quot;: 9,
                    &quot;lectura_anterior&quot;: 5.9,
                    &quot;consumo_calculado&quot;: 3.1,
                    &quot;consumo_facturado&quot;: 3,
                    &quot;limite_sobreconsumo&quot;: 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.

```http
https://libredte.cl/api/dte/documentos/generar?getXML=0&amp;links=0&amp;email=0&amp;retry=10&amp;gzip=0
```

| Parámetro | Tipo | Descripción                                                                                                                |
| --------- | ---- | -------------------------------------------------------------------------------------------------------------------------- |
| `getXML`  | int  | `1`: Includes the XML in the response.&lt;br&gt; `0`: Does not include the XML.          |
| `links`   | int  | `1`: Includes links associated with the DTE.&lt;br&gt; `0`: Does not include links. |
| `email`   | int  | `1`: Sends the document by email to the recipient.&lt;br&gt; `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):

```json
{
    &quot;emisor&quot;: 76123456,
    &quot;receptor&quot;: 66666666,
    &quot;dte&quot;: 39,
    &quot;codigo&quot;: &quot;557ccc1706a77a212354d0f1734fd0adc&quot;
}
```

## 3. [GET] Generate PDF of an Issued DTE

This endpoint allows you to generate a PDF version of a DTE issued in LibreDTE.

```http
https://libredte.cl/api/dte/dte_emitidos/pdf/:dte/:folio/:emisor?formato=general&amp;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](https://www.libredte.cl/docs/api#/Facturaci%C3%B3n/pdfDeUnDteEmitido).

&lt;twig:block-cta
    class=&quot;my-4 rounded p-4&quot;
    title=&quot;Need Additional Help?&quot;
    content=&#039;If you need help with the points mentioned in the document, please open a support ticket.&#039;
    buttonText=&quot;I need help&quot;
    buttonUrl=&quot;/help?topic=technical&quot;
/&gt;


    

---

Last updated on 25/08/2026
#api, #english
