> ## Documentation Index
> Fetch the complete documentation index at: https://docs-mx.taxo.ws/llms.txt
> Use this file to discover all available pages before exploring further.

# CFDI Invoices

> Understanding Mexico's electronic invoicing system and CFDI document extraction

## Overview

**CFDI (Comprobante Fiscal Digital por Internet)** is Mexico's electronic invoicing system mandated by SAT. All business transactions in Mexico must be documented using CFDI invoices, which are digitally signed XML documents that can also have PDF representations.

## What are CFDI Invoices?

CFDI invoices are the foundation of Mexico's digital tax system. Every sale, purchase, service, or transfer of goods must be documented with a CFDI that:

* Contains structured data in XML format
* Is digitally signed by the issuer
* Is validated and stamped by SAT
* Includes unique fiscal identifiers (UUID)

> [accordion] CFDI Structure
>
> Every CFDI contains essential fiscal information:
>
> ```xml theme={null}
> <cfdi:Comprobante>
>   <cfdi:Emisor Rfc="GACJ841128A87" Nombre="Empresa Emisora"/>
>   <cfdi:Receptor Rfc="XAXX010101000" Nombre="Receptor"/>
>   <cfdi:Conceptos>
>     <cfdi:Concepto Descripcion="Product/Service" Importe="1000.00"/>
>   </cfdi:Conceptos>
>   <cfdi:Impuestos TotalImpuestosTrasladados="160.00"/>
>   <tfd:TimbreFiscalDigital UUID="12345678-1234-1234-1234-123456789012"/>
> </cfdi:Comprobante>
> ```

> [accordion] Digital Signatures
>
> CFDI invoices include multiple digital signatures:
>
> * **Issuer Signature**: Created by the issuer using their FIEL
> * **SAT Stamp**: Applied by SAT's authorized providers (PAC)
> * **UUID**: Unique identifier assigned by SAT for each CFDI

> [accordion] Available Formats
>
> CFDI invoices can be retrieved in multiple formats:
>
> * **XML**: Original structured data with all fiscal information
> * **PDF**: Human-readable representation for printing and sharing
> * **Metadata**: Extracted key fields for integration

## CFDI Types and Use Cases

### Invoice Directions

> [card] Inbound Invoices
>
> **Received by your company**
>
> * Supplier invoices
> * Expense documentation
> * Accounts payable
> * Tax deductible expenses

> [card] Outbound Invoices
>
> **Issued by your company**
>
> * Customer invoices
> * Revenue documentation
> * Accounts receivable
> * Tax obligations

### Common CFDI Document Types

| Type Code | Description | Use Case |
| - | - | - |
| `I` | Ingreso (Income) | Sales invoices, service billing |
| `E` | Egreso (Expense) | Credit notes, refunds |
| `T` | Traslado (Transfer) | Goods movement, inventory transfers |
| `P` | Pago (Payment) | Payment complements |
| `N` | Nómina (Payroll) | Employee salary payments |

## Extracting CFDI Invoices

### Basic Extraction Request

```json theme={null}
{
  "subject": {
    "identifier": "GACJ841128A87"
  },
  "credentials": {
    "SAT": {
      "type": "USERNAME_PASSWORD",
      "username": "GACJ841128A87",
      "password": "CIEC_PASSWORD"
    }
  },
  "options": {
    "informationType": "INVOICE",
    "direction": "INBOUND",
    "period": {
      "from": "2024-01-01",
      "to": "2024-01-31"
    }
  }
}
```

### Advanced Filtering

```json Specific Issuer theme={null}
{
  "filters": {
    "emitter": {
      "operator": "equals",
      "value": "ABC123456789"
    }
  }
}
```

```json Multiple Issuers theme={null}
{
  "filters": {
    "emitter": {
      "operator": "in", 
      "value": ["ABC123456789", "XYZ987654321"]
    }
  }
}
```

```json Amount Range theme={null}
{
  "filters": {
    "amount": {
      "operator": "between",
      "value": [1000, 50000]
    }
  }
}
```

## CFDI Data Fields

### Key Invoice Information

When you extract CFDI invoices, you get access to structured data including:

> [accordion] Basic Information
>
> * **UUID**: Unique fiscal identifier
> * **Issue Date**: When the invoice was created
> * **Certification Date**: When SAT validated the invoice
> * **Total Amount**: Invoice total including taxes
> * **Currency**: Usually MXN (Mexican Peso)

> [accordion] Parties
>
> **Issuer (Emisor)**:
>
> * RFC, business name, address
> * Tax regime information
>
> **Recipient (Receptor)**:
>
> * RFC, name, address
> * CFDI usage purpose

> [accordion] Line Items
>
> Each invoice contains detailed line items:
>
> * Product/service description
> * Quantity and unit price
> * Tax classifications
> * Discount information

> [accordion] Tax Information
>
> Detailed tax breakdown:
>
> * VAT (IVA) calculations
> * Retention taxes
> * Other applicable taxes
> * Tax rates and amounts

## Best Practices for CFDI Processing

### Data Validation

> [!TIP]
>
> Always validate CFDI invoices against SAT's official schemas to ensure data integrity.

```javascript theme={null}
// Example validation check
function validateCFDI(cfdiData) {
  // Check required fields
  if (!cfdiData.uuid || !cfdiData.issueDate) {
    throw new Error('Missing required CFDI fields');
  }
  
  // Validate RFC format
  if (!isValidRFC(cfdiData.emitter.rfc)) {
    throw new Error('Invalid issuer RFC format');
  }
  
  // Check tax calculations
  if (!validateTaxCalculations(cfdiData.taxes)) {
    throw new Error('Tax calculation mismatch');
  }
}
```

### Duplicate Detection

```javascript theme={null}
// Prevent duplicate processing using UUID
function isDuplicateCFDI(uuid, processedInvoices) {
  return processedInvoices.has(uuid);
}

// Track processed invoices
const processedInvoices = new Set();

invoices.forEach(invoice => {
  if (!isDuplicateCFDI(invoice.uuid, processedInvoices)) {
    processInvoice(invoice);
    processedInvoices.add(invoice.uuid);
  }
});
```

### Storage Recommendations

> [!WARNING]
>
> **Legal Requirement**: Mexican law requires businesses to store CFDI invoices for at least 5 years in their original XML format.

* Store both XML and PDF versions
* Maintain original digital signatures
* Implement backup and disaster recovery
* Use secure, encrypted storage solutions

## Integration Examples

### Accounting System Integration

```javascript theme={null}
// Extract and process CFDI invoices for accounting
async function syncCFDIToAccounting(extractionId) {
  const status = await getExtractionStatus(extractionId);
  
  if (status.status === 'COMPLETED') {
    for (const doc of status.documents) {
      if (doc.type === 'INVOICE') {
        // Download XML for structured data
        const xmlData = await downloadDocument(extractionId, doc.id, 'XML');
        
        // Parse CFDI data
        const cfdiData = parseCFDI(xmlData);
        
        // Create accounting entry
        await createAccountingEntry({
          invoiceNumber: cfdiData.uuid,
          vendor: cfdiData.emitter.name,
          amount: cfdiData.total,
          taxAmount: cfdiData.taxes.total,
          date: cfdiData.issueDate,
          status: 'pending_payment'
        });
      }
    }
  }
}
```

### Expense Management

```javascript theme={null}
// Process inbound invoices for expense tracking
async function processExpenseInvoices(invoices) {
  const expenses = invoices.map(invoice => ({
    id: invoice.uuid,
    vendor: invoice.emitter.name,
    amount: invoice.total,
    category: categorizeExpense(invoice.items),
    taxDeductible: isDeductible(invoice),
    approvalRequired: invoice.total > 5000
  }));
  
  await bulkCreateExpenseRecords(expenses);
}
```

## Troubleshooting CFDI Issues

### Common Problems

> [accordion] Invalid CFDI Format
>
> **Symptoms**: XML parsing errors, missing required fields
>
> **Solutions**:
>
> * Verify CFDI was properly issued by authorized PAC
> * Check for complete digital signatures
> * Validate against SAT's official XSD schemas

> [accordion] Missing PDF Representation
>
> **Symptoms**: Only XML available, no PDF format
>
> **Solutions**:
>
> * Some CFDIs may not have PDF representations
> * Generate PDF from XML data if needed
> * Check with issuer for PDF availability

> [accordion] Large Volume Processing
>
> **Symptoms**: Timeouts, memory issues with large extractions
>
> **Solutions**:
>
> * Process invoices in smaller date ranges
> * Implement pagination for large datasets
> * Use streaming processing for XML parsing

## Next Steps

> [card] [SAT API Quickstart](https://docs-mx.taxo.ws/countries/mx/tax-authorities/sat/quickstart.md)
>
> Start extracting CFDI invoices from SAT

> [card] [Use Cases](https://docs-mx.taxo.ws/countries/mx/use-cases/accounting-automation.md)
>
> See real-world CFDI integration examples

> [card] [Webhooks](https://docs-mx.taxo.ws/countries/mx/tax-authorities/sat/webhooks/overview.md)
>
> Get notified when CFDI extractions complete

> [card] [Troubleshooting](https://docs-mx.taxo.ws/global/troubleshooting/common-errors.md)
>
> Resolve common CFDI processing issues


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.