API Integration
General Integration Flow
The process for issuing a DTE (Electronic Tax Document) consists of the following steps:
- Data Preparation – Structuring the document’s information.
- Consuming REST Services - Communicating with the LibreDTE API.
- 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.
Other scenarios should be constructed using the official documentation provided by the SII (Chilean Internal Revenue Service).
2. Consuming the REST Web Services
You have several options to interact with LibreDTE’s REST services:
-
Use the official SDKs provided by LibreDTE for your programming language. You can find them here: LibreDTE Client Repositories.
-
Develop your own client (SDK) to consume the services directly from your application.
-
Use an HTTP library appropriate for your language to handle REST 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:
- Issue a temporary DTE
- Generate a real DTE from the temporary version.
- Check the status of the DTE submitted to the SII.
- Retrieve the PDF of the finalized DTE.
Note: 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
To issue a DTE and obtain its corresponding PDF, your code must perform the API calls illustrated in the following sequence diagram:
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.
- DTE XML diagram: DTE Diagram
- Electronic Receipts (Boletas):
- Receipt format description: Electronic Receipts Format
- Receipt XML diagram: Receipt Diagram
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.