Overview
The Tresa Contafy API provides powerful endpoints to upload, parse, and validate Mexican CFDI (Comprobante Fiscal Digital por Internet) invoices. The system automatically:- Parses XML CFDI files (versions 3.3 and 4.0)
- Validates RFC, fiscal regime, and UUID duplicates
- Classifies as income (factura) or expense (gasto)
- Handles payment complements (Complemento de Pago)
- Performs automatic payment matching for PPD invoices
Authentication
All invoice endpoints require authentication. Include your JWT token in the Authorization header:Uploading Invoices
Prepare your CFDI XML file
Ensure you have a valid CFDI XML file (version 3.3 or 4.0). The file should have a
.xml extension.Select a profile
You need a profile ID to associate the invoice with. If you don’t have one, create a profile first.
Upload Endpoint
Request Parameters
The CFDI XML file to upload (max 10MB)
UUID of the profile to associate the invoice with
Response
Testing with Parse Endpoint
Before uploading, you can test XML parsing without saving to the database:The
/parse endpoint validates and extracts data but does not save the invoice to the database. Use it for testing and validation.Automatic Classification
The API automatically classifies CFDI documents based on the profile’s RFC:- Income Invoice (Factura): Profile RFC matches the
rfcEmisor(issuer) - Expense (Gasto): Profile RFC matches the
rfcReceptor(receiver) - Payment Complement: Detected by
tipo: "COMPLEMENTO_PAGO"
Payment Types
PUE (Pago en Una Exhibición)
Single payment invoices are automatically marked as paid:PPD (Pago en Parcialidades o Diferido)
Installment or deferred payment invoices require payment complements:Payment Complements (Complemento de Pago)
Upload payment complements the same way as invoices. The system automatically:- Validates the complement against existing invoices
- Matches it to related invoices by UUID
- Updates payment status of matched invoices
Validation Errors
The API performs comprehensive fiscal validations:Common Validation Errors
Rate Limits
Invoice upload endpoints have specific rate limits:- 300 requests per 5 minutes per user
- Applies to both
/parseand/uploadendpoints - Based on user ID (not IP address)
Retrieving Invoices
List All Invoices
Query Parameters
Filter by profile UUID
Filter by month (1-12)
Filter by year
Filter by type:
PUE, PPD, or COMPLEMENTO_PAGOFilter by 3-digit SAT fiscal regime code
Search by RFC, name, or concept
Page number for pagination
Results per page (max 100)
Get Single Invoice
Deleting Invoices
Best Practices
- Always validate first: Use the
/parseendpoint to test XML files before uploading - Handle duplicates gracefully: Check for HTTP 409 errors and inform users
- Monitor rate limits: Implement exponential backoff for bulk uploads
- Store profileId: Cache the profile ID to avoid extra lookups
- Process payment complements: Upload payment complements after their related invoices
Plan Limits
Invoice uploads are subject to your subscription plan:- FREE: 1 profile, unlimited invoices
- BASIC: 5 profiles, unlimited invoices
- PRO: 20 profiles, unlimited invoices
- ENTERPRISE: Unlimited profiles and invoices
While invoices per month are unlimited on all plans, profile limits apply. See Subscription Management for details.