Overview
The invoice generation process involves two steps:- Generate the invoice object with
generateInvoice()- Creates the complete invoice structure and calculates the access key - Convert to XML with
generateInvoiceXml()- Transforms the invoice object into XML format required by SRI
Generating an Invoice
Prepare your invoice data
Create an
InvoiceInput object with all required tax, invoice, and detail information:The
claveAcceso (access key) is automatically generated based on the invoice data. You don’t need to provide it manually.Generate the invoice object
Call The function returns:
generateInvoice() to create the invoice structure and access key:invoice: Complete invoice object with XML structureaccessKey: 49-digit unique identifier for the invoice
Access Key Generation
The access key is automatically generated using the following components:| Component | Description | Source |
|---|---|---|
| Date | Emission date (DDMMYYYY) | infoFactura.fechaEmision |
| Document Code | Type of document (01 for invoice) | infoTributaria.codDoc |
| RUC | Tax identification number | infoTributaria.ruc |
| Environment | Testing (1) or Production (2) | infoTributaria.ambiente |
| Establishment | Establishment code | infoTributaria.estab |
| Emission Point | Point of emission | infoTributaria.ptoEmi |
| Sequential | Sequential number | infoTributaria.secuencial |
| Numeric Code | Random 8-digit number | Auto-generated |
| Emission Type | Always “1” | Fixed |
| Verification Digit | Modulus 11 checksum | Calculated |
Complete Example
Here’s a minimal working example:Next Steps
Sign the Document
Learn how to digitally sign the XML with your P12 certificate
Submit to SRI
Submit the signed document to SRI’s reception endpoint
API Reference
For detailed type information and all available fields:Invoice Types
View complete type definitions for InvoiceInput and Invoice