Quickstart Guide
This guide will walk you through creating your first electronic invoice with the SUNAT Electronic Invoicing API. You’ll be up and running in about 10 minutes.This quickstart assumes you have already completed the installation. If not, please complete the installation first.
Prerequisites
Before you begin, make sure you have:Completed the installation and database migration
Obtained your SUNAT credentials (RUC, SOL user, SOL password)
A valid SUNAT digital certificate (.pem format)
An API client (Postman, Insomnia, or curl)
Step 1: Initialize the System
First, create the initial super admin user. This is a one-time setup that initializes the roles and permissions.Step 2: Authenticate
Login to get an access token:For all subsequent requests, include the token in the
Authorization header:Step 3: Create a Company
Register your company with SUNAT credentials:company_id from the response.
Step 4: Create a Branch
Create a branch (sucursal) for your company:branch_id from the response.
Step 5: Create Document Series
Create a correlative series for invoices:Document types:
01= Factura (Invoice)03= Boleta de Venta (Sales Receipt)07= Nota de Crédito (Credit Note)08= Nota de Débito (Debit Note)
Step 6: Upload SUNAT Certificate
Place your certificate in the correct location:The certificate password will be requested during the conversion. The output
.pem file includes both the private key and certificate in one file.Step 7: Create Your First Invoice
Now create an invoice and send it to SUNAT:Step 8: Send to SUNAT
Send the created invoice to SUNAT for validation:SUNAT Response Codes:
ACEPTADO- Document acceptedRECHAZADO- Document rejected (check error code)PENDIENTE- Not yet sent to SUNAT
Step 9: Download Files
Once accepted, you can download the generated files:- XML
- CDR (SUNAT Response)
- PDF
Step 10: Generate PDF
Generate a professional PDF with QR code:- Company logo and information
- Client details
- Itemized products/services
- Tax calculations (IGV, etc.)
- QR code for verification
- Digital hash
Common Issues
Certificate Error
Certificate Error
Error: Verify file permissions:
Archivo de certificado no encontradoSolution: Ensure your certificate is placed at:Authentication Failed
Authentication Failed
Error:
Credenciales incorrectas or Usuario bloqueadoSolution:- Verify SOL credentials are correct
- Ensure you’re using beta credentials for beta environment
- Check if user is active in database
SUNAT Rejection
SUNAT Rejection
Error: Various SUNAT error codesSolution: Check the error code in SUNAT documentation:
2335- RUC not authorized2324- Invalid certificate1033- Document already exists
- Verify RUC matches certificate
- Check certificate is not expired
- Ensure document series is unique
Database Connection Error
Database Connection Error
Error:
Database connection failedSolution:- Check
.envdatabase credentials - Verify MySQL/PostgreSQL is running
- Test connection:
php artisan migrate:status
Next Steps
API Reference
Explore all available endpoints and parameters
Advanced Features
Learn about credit notes, debit notes, and perceptions
Postman Collection
Download ready-to-use Postman examples
Production Deployment
Prepare for production environment
