Bulk XML download

Bulk download (the SAT service that delivers the CFDIs a taxpayer issued and received) automatically retrieves three types of documents from the SAT (Mexico's tax authority, Servicio de Administración Tributaria): CFDIs (Mexico's electronic invoices), which are the complete invoices in XML; metadata, a summary of each CFDI; and withholding CFDIs (CFDI de Retenciones e Información de Pagos, the CFDIs that report taxes withheld from a payment). Use them to generate your electronic accounting (contabilidad electrónica, the accounting records Mexican taxpayers send to the SAT in XML) and journal entries; reconcile accounts payable, accounts receivable, and bank transactions; prepare audits; automate your supply chain and supplier payments; and verify the CFDIs you receive.

Bulk download is based on Articles 29 and 29-A of the CFF (Código Fiscal de la Federación, Mexico's Federal Tax Code), which set the obligation to issue CFDIs and their requirements. It's also based on Rule 2.7.6.4 of the Resolución Miscelánea Fiscal (RMF, the SAT's annual tax rules), which regulates the bulk download service for CFDIs and withholding CFDIs.

Requirements

Bulk download requires the taxpayer's current e.firma (the SAT advanced electronic signature that identifies a taxpayer, formerly FIEL). The e.firma and the CSD (Certificado de Sello Digital, the digital seal certificate used to sign CFDIs) each consist of a .cer file, a .key file, and a password, but they serve different purposes. The CSD only seals invoices, and the e.firma is a general-purpose electronic signature used for everything else, including bulk download.

Download types

Fiscalapi downloads three types of documents from the SAT. You choose the type with the satQueryTypeId field when you create a download rule.

TypeAPI valueDescription
CFDI"CFDI"Complete invoices in XML. Includes only active CFDIs.
Metadata"Metadata"A summary of each CFDI: UUID (folio fiscal, the unique ID the PAC assigns when it stamps a CFDI), issuer, recipient, amounts, and status. Includes active and canceled CFDIs.
Withholding CFDIs"Retenciones"CFDIs that report withholdings and payment information. Includes only active CFDIs.

Concepts

These are the bulk download concepts, from the most general to the most specific:

ConceptWhat it is
PersonA taxpayer, either an individual (persona física) or a legal entity (persona moral): a company, a customer, or an organization. See issuers or recipients.
Download ruleA template you create once with the fixed data for a person's downloads: document type, issued or received, and status, for example active received CFDIs. Fiscalapi reuses it to create requests.
Download requestA specific request to the SAT, created from a rule. It inherits the rule's data, adds the period (start date and end date), and tracks its status, resilience, and retries.
PackageA ZIP file the SAT generates for a finished request. A request can produce one or more packages, and Fiscalapi processes them to extract their content.
XMLWith the CFDI type, Fiscalapi reads each XML file in the packages and saves its data: issuer, recipient, line items, taxes, and complements (complementos, XML extensions the SAT defines for specific operations). You query that data from the API without processing the XML.
MetadataWith the Metadata type, Fiscalapi saves the summary of each CFDI (UUID, issuer and recipient RFCs, date, amount, type, and status) as a record you can query and filter from the API.

Entity hierarchy

API responses follow this hierarchy:

Regla de descarga
  └── Solicitud de descarga
        └── Paquete de descarga
              ├── Xml[]          (cuando satQueryTypeId = "CFDI")
              └── MetadataItem[] (cuando satQueryTypeId = "Metadata")

A rule generates requests over time: Fiscalapi creates at least one automatic request per day, and you can create as many manual requests as you need with the API. Each request produces one or more packages, and each package contains the extracted XML files or metadata.

Test environment

The SAT doesn't offer a test environment for bulk download. That's why Fiscalapi's test environment includes its own simulator, which reproduces the complete flow. To use it, follow these three steps.

Step 1: Set up your tenant to issue CFDIs

Follow the quickstart to set up your tenant (the space in Fiscalapi that holds your issuers, recipients, credits, and data): create an issuer person, upload its test certificates, and verify that you can issue invoices.

Step 2: Issue test invoices

Issue a few test invoices by reference (invoice by reference: you send the IDs of people and products already saved in Fiscalapi), with the API or from the dashboard. The simulation takes your most recent invoices whose issuer is a person registered in your tenant, so invoices by value (invoice by value: you send every issuer, recipient, and item value in the request) don't work for this step. You can use any HTTP client or the Postman collection, and the invoice tutorial explains the process in detail.

Step 3: Simulate bulk download from the dashboard

The simulator needs invoices issued in your tenant. Once you have them, go to Descarga CFDI > Reglas de descarga (CFDI download > Download rules) in the dashboard's side menu and click Agregar (Add) in the upper-right corner.

Create a test download rule
Create a test download rule

Test flow result

When you complete the flow, Fiscalapi creates a test download rule with status Aprobada (Approved) and a download request with status Completada (Completed), with the downloaded CFDIs (XML) and their metadata. You can also start the simulation with the API:

POST /api/v4/download-rules/test

How it works in production

To use bulk download in production, follow these steps in the dashboard:

  1. Turn on the Bulk CFDI download add-on (an extra you add to your subscription, such as Auto CFDI invoicing) in Compras en línea > Módulos adicionales (Billing > Add-ons).
  2. Create a person with the RFC you want to download documents for and upload its e.firma.
  3. In Descarga CFDI > Reglas de descarga (CFDI download > Download rules), create a download rule and assign it to that person.
  4. In Descarga CFDI > Solicitudes de descarga (CFDI download > Download requests), create a download request and assign it to the rule.
Download requests table
Download requests table

Request types

TypeAPI valueDescription
Automatic"Automatica"Fiscalapi creates it every day at 1:05 a.m. central Mexico time for each approved rule. It covers the entire previous day, from 00:00:00 to 23:59:59.
Manual"Manual"You create it with the API, with downloadRequestTypeId set to "Manual" and the period you need. You can create as many as you need.

Lifecycle

Download rules and requests go through several statuses while they're processed. Check them to track the progress of your downloads.

Download rule statuses

IDStatusDescription
1Pendiente (Pending)The rule was created and is awaiting approval.
2Aprobada (Approved)The rule is active and generates automatic requests.
3Rechazada (Rejected)The rule was rejected and doesn't generate requests.
4Suspendida (Suspended)Fiscalapi suspended the rule because of a configuration error, such as an expired or missing e.firma. It doesn't generate requests until you fix the error and the rule is approved again.
-1Abandonada (Abandoned)The rule was canceled, deactivated, or couldn't be processed.
Pendiente (1) --> Aprobada (2) --> Abandonada (-1)
                             └--> Rechazada (3)

Request statuses (Fiscalapi)

IDStatusDescription
1Esperando SAT (Waiting for SAT)Fiscalapi sent the request to the SAT and is waiting for its response.
2Esperando API (Waiting for API)The SAT responded and Fiscalapi is processing the downloaded packages.
3Completada (Completed)Fiscalapi downloaded and processed all the packages.
-1Abandonada (Abandoned)The request was canceled, failed permanently, or the SAT reported that no documents match the criteria.
EsperandoSat (1) --> EsperandoApi (2) --> Completada (3)
                                      └--> Abandonada (-1)

Request statuses at the SAT

IDStatusDescription
0Desconocido (Unknown)Initial status: Fiscalapi hasn't checked the request with the SAT yet.
1Aceptada (Accepted)The SAT accepted the request and is processing it.
2En proceso (In progress)The SAT is generating the packages.
3Terminada (Finished)The packages are ready to download.
4ErrorAn error occurred at the SAT.
5Rechazada (Rejected)The SAT rejected the request.
6Vencida (Expired)The request expired at the SAT.
-1Abandonada (Abandoned)Fiscalapi abandons the request after a permanent error or when the SAT rejects it, for example because no documents match the criteria.
Desconocido (0) --> Aceptada (1) --> EnProceso (2) --> Terminada (3)
                                                   └--> Error (4) --> Abandonada (-1)
                                                   └--> Rechazada (5) --> Abandonada (-1)
                                                   └--> Vencida (6) --> Abandonada (-1)

Automatic processing

From a rule's approval date, and while the rule stays in the Aprobada (Approved) status, Fiscalapi runs the download without manual intervention:

StageFrequencyWhat Fiscalapi does
Request generationEvery day at 1:05 a.m. central Mexico timeCreates one automatic request per rule to download the previous day's documents, from 00:00:00 to 23:59:59.
Verification and downloadEvery hourChecks the status of pending requests with the SAT and downloads the available packages.
Package processingEvery two hoursExtracts the XML files or the metadata from the downloaded packages.
RetriesAfter a transient errorRetries the download or the processing until the request reaches a final status, Completada (Completed) or Abandonada (Abandoned).

Validation rules

Download rule validations

FieldValidation
personIdRequired, exactly 36 characters.
satQueryTypeIdOne of the API values of the download types.
downloadTypeId"Emitidos" or "Recibidos".
satInvoiceStatusId"Vigente" or "Cancelado".
descriptionRequired, up to 100 characters.

Forbidden combinations

CombinationReason
CFDI + CanceladoThe SAT delivers canceled CFDIs, issued or received, only as metadata.
Retenciones + CanceladoWithholding CFDIs only accept the Vigente status.

Period limits

Query typeMaximum period per request
CFDI and metadata31 days (1 month)
Withholding CFDIs400 days (13 months)

Uniqueness rule

You can't have two active rules with the same RFC, query type (satQueryTypeId), issued or received (downloadTypeId), and invoice status (satInvoiceStatusId). A rule is active in any status except Abandonada (Abandoned). Uniqueness is checked by RFC, so it applies even if the RFC is registered under two people.

SAT status codes

The SAT responds to each bulk download operation with one of these codes:

CodeDescription
0Desconocido (Unknown)
300Usuario no válido (Invalid user)
301XML mal formado (Malformed XML)
302Sello mal formado (Malformed seal)
303Sello no corresponde con RFC (Seal doesn't match the RFC)
304Certificado revocado o caduco (Certificate revoked or expired)
305Certificado inválido (Invalid certificate)
404Error no controlado (Unhandled error)
5000Solicitud recibida con éxito (Request received successfully)
5001Tercero no autorizado (Unauthorized third party)
5002Solicitudes de por vida agotadas (Lifetime request limit reached)
5003Tope máximo de elementos (Maximum number of items reached)
5004Información no encontrada (No information found)
5005Solicitud duplicada (Duplicate request)
5007Paquete no existe (Package doesn't exist)
5008Máximo de descargas permitidas (Maximum allowed downloads reached)
5011Límite de descargas por folio por día (Daily download limit per UUID)
5012No permite descarga de cancelados (Downloading canceled CFDIs isn't allowed)

Related resources

Was this page helpful?