# SAT downloads

> The invoices an issuer received or issued, straight from SAT with their XML: SAT's bulk download with the issuer's e.firma, with an event when it finishes.

With SAT's bulk download you bring every invoice an issuer **received** (its expenses, from any supplier) or **issued** (even if it didn't make them with Fiscalisto), with its XML. It's useful for accounting, for reconciling payments or for checking suppliers against [SAT's lists](https://fiscalisto.com/en/docs/api/listas-del-sat). In production they use timbres according to how many invoices they bring; free in test mode.

SAT takes from a few minutes to a few hours to prepare each download. You request it, carry on with your work and `sat_download.completed` arrives when the invoices are ready.

## In test mode and in production

- **In production** SAT is asked with the issuer's e.firma, which you store once (below).
- **In test mode** SAT has no test environment for this, so it isn't asked: the download finishes instantly with sample invoices between the issuer and SAT's test RFCs, with their XML and their event. Asking for the same again brings the same invoices, without duplicating them. No e.firma needed: the test issuer always carries `sat_downloads.available: true`, and in `efirma_expires_at` when the e.firma it stores in production for the same RFC expires (or the one you send in test mode with `keep_for_downloads: true`, which is checked the same but not stored).

## Store the issuer's e.firma

An RFC of your company (`type: "own"`) uses the e.firma the company already stored in the app (**Ajustes › Credenciales**): there's no need to send it again, and the issuer carries `sat_downloads.available: true` and its `efirma_expires_at` while it's valid. The one you send through the API for that RFC is also kept in the app. The CSD isn't needed to download or to read the invoices: the CSD is only for stamping.

For a connected issuer (`type: "connected"`), in production, send the e.firma (the `.cer` and `.key` in base64 and its password) with `keep_for_downloads: true`. It's checked to be a valid e.firma of that RFC and stored encrypted, as in the app. If the issuer hasn't signed the PAC contract yet and already has its CSD, the same call signs it.

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/issuers/iss_OufpKqnrvx9p/efirma \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{
    \"cer\": \"$(base64 < efirma.cer | tr -d '\n')\",
    \"key\": \"$(base64 < efirma.key | tr -d '\n')\",
    \"password\": \"$EFIRMA_PASSWORD\",
    \"keep_for_downloads\": true
  }"
```

```ts tab="TypeScript"
import { readFile } from "node:fs/promises";
import { Fiscalisto } from "fiscalisto";

// The key comes from FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

const issuer = await fiscalisto.issuers.signEfirma("iss_OufpKqnrvx9p", {
  cer: (await readFile("efirma.cer")).toString("base64"),
  key: (await readFile("efirma.key")).toString("base64"),
  password: process.env.EFIRMA_PASSWORD!,
  keep_for_downloads: true,
});
```

```python tab="Python"
import base64
import os

from fiscalisto import Fiscalisto

# The key comes from FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

issuer = fiscalisto.issuers.sign_efirma("iss_OufpKqnrvx9p", {
    "cer": base64.b64encode(open("efirma.cer", "rb").read()).decode(),
    "key": base64.b64encode(open("efirma.key", "rb").read()).decode(),
    "password": os.environ["EFIRMA_PASSWORD"],
    "keep_for_downloads": True,
})
```

```php tab="PHP"
<?php

use Fiscalisto\Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

$issuer = $fiscalisto->issuers->signEfirma('iss_OufpKqnrvx9p', [
    'cer' => base64_encode(file_get_contents('efirma.cer')),
    'key' => base64_encode(file_get_contents('efirma.key')),
    'password' => getenv('EFIRMA_PASSWORD'),
    'keep_for_downloads' => true,
]);
```

```go tab="Go"
package main

import (
	"encoding/base64"
	"context"
	"fmt"
	"log"
	"os"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// The key comes from FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	issuer, err := client.Issuers.SignEfirma(ctx, "iss_OufpKqnrvx9p", &fiscalisto.SignEfirmaParams{
		Cer:              readBase64("efirma.cer"),
		Key:              readBase64("efirma.key"),
		Password:         os.Getenv("EFIRMA_PASSWORD"),
		KeepForDownloads: fiscalisto.Bool(true),
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(issuer.ID)
}

func readBase64(path string) string {
	b, err := os.ReadFile(path)
	if err != nil {
		log.Fatal(err)
	}
	return base64.StdEncoding.EncodeToString(b)
}
```

```java tab="Java"
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Base64;
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.model.SignEfirmaParams;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var issuer = fiscalisto.issuers().signEfirma("iss_OufpKqnrvx9p", new SignEfirmaParams()
        .setCer(Base64.getEncoder().encodeToString(Files.readAllBytes(Path.of("efirma.cer"))))
        .setKey(Base64.getEncoder().encodeToString(Files.readAllBytes(Path.of("efirma.key"))))
        .setPassword(System.getenv("EFIRMA_PASSWORD"))
        .setKeepForDownloads(true));
System.out.println(issuer.getId());
```

```csharp tab="C#"
using Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var issuer = await fiscalisto.Issuers.SignEfirmaAsync("iss_OufpKqnrvx9p", new SignEfirmaParams
{
    Cer = Convert.ToBase64String(File.ReadAllBytes("efirma.cer")),
    Key = Convert.ToBase64String(File.ReadAllBytes("efirma.key")),
    Password = Environment.GetEnvironmentVariable("EFIRMA_PASSWORD")!,
    KeepForDownloads = true,
});
```

The issuer carries `sat_downloads.available: true` and when its e.firma expires in `sat_downloads.efirma_expires_at`. To delete it: `DELETE /v1/issuers/{id}/efirma`. The issuer keeps stamping; it can only no longer request downloads.

> **With the owner's permission.** Ask for the e.firma only with the RFC owner's permission and tell them what it's for. With it, all their invoices at SAT can be queried.

## Request a download

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/sat_downloads \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "direction": "received", "from": "2026-09-01", "to": "2026-09-30" }'
```

```ts tab="TypeScript"
import { Fiscalisto } from "fiscalisto";

// The key comes from FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

const satDownload = await fiscalisto.satDownloads.create({
  direction: "received",
  from: "2026-09-01",
  to: "2026-09-30",
});
```

```python tab="Python"
from fiscalisto import Fiscalisto

# The key comes from FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

sat_download = fiscalisto.sat_downloads.create({
    "direction": "received",
    "from": "2026-09-01",
    "to": "2026-09-30",
})
```

```php tab="PHP"
<?php

use Fiscalisto\Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

$satDownload = $fiscalisto->satDownloads->create([
    'direction' => 'received',
    'from' => '2026-09-01',
    'to' => '2026-09-30',
]);
```

```go tab="Go"
package main

import (
	"context"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// The key comes from FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	satDownload, err := client.SatDownloads.Create(ctx, &fiscalisto.CreateSatDownloadParams{
		Direction: fiscalisto.String("received"),
		From:      "2026-09-01",
		To:        "2026-09-30",
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(satDownload.ID)
}
```

```java tab="Java"
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.model.CreateSatDownloadParams;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var satDownload = fiscalisto.satDownloads().create(new CreateSatDownloadParams()
        .setDirection("received")
        .setFrom("2026-09-01")
        .setTo("2026-09-30"));
System.out.println(satDownload.getId());
```

```csharp tab="C#"
using Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var satDownload = await fiscalisto.SatDownloads.CreateAsync(new CreateSatDownloadParams
{
    Direction = "received",
    From = "2026-09-01",
    To = "2026-09-30",
});
```

Returns `202` with the download (`sdl_…`) in `status: "processing"` (in test mode it already comes `completed`):

```json
{
  "id": "sdl_OufpKqnrvx9p3n8vQd2LkW7mZr1XyT5uBc",
  "object": "sat_download",
  "livemode": true,
  "issuer": "iss_OufpKqnrvx9p",
  "direction": "received",
  "from": "2026-09-01",
  "to": "2026-09-30",
  "type": null,
  "counterparty_tax_id": null,
  "uuid": null,
  "status": "processing",
  "new_invoices": null,
  "error": null,
  "created_at": "2026-10-24T10:20:00-06:00",
  "completed_at": null
}
```

| Field | What it asks for |
| --- | --- |
| `direction` | `received` (default) or `issued`. |
| `from`, `to` | The days, inclusive. Up to one year per download, from January 1 five years ago (what SAT provides) to today. |
| `type` | Only one document type: `I`, `E`, `P`, `T` or `N`. |
| `counterparty_tax_id` | Only those of one supplier (received) or one customer (issued). |
| `uuid` | A single invoice, by its folio fiscal. |

Received invoices arrive **current**: SAT only delivers a received invoice's XML while it isn't cancelled.

## When it finishes

The `sat_download.completed` event arrives with the download and `new_invoices`, how many new invoices it brought (the ones you already had aren't counted twice). If SAT couldn't, `sat_download.failed` arrives with the reason in `error`, for example an expired e.firma. You can also look it up with `GET /v1/sat_downloads/{id}` or list them with `GET /v1/sat_downloads`.

SAT limits how many times exactly the same thing can be requested (the same period with the same filters). If they run out, the response is `sat_request_rejected`: request a slightly different period.

## The invoices

```bash tab="cURL"
curl "https://api.fiscalisto.com/v1/sat_invoices?direction=received&date_gte=2026-09-01&limit=20" \
  -H "Authorization: Bearer $FISCALISTO_API_KEY"
```

```ts tab="TypeScript"
import { Fiscalisto } from "fiscalisto";

// The key comes from FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

for await (const item of fiscalisto.satInvoices.list({
  direction: "received",
  date_gte: "2026-09-01",
  limit: 20,
})) {
  console.log(item.id);
}
```

```python tab="Python"
from fiscalisto import Fiscalisto

# The key comes from FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

for item in fiscalisto.sat_invoices.list({
    "direction": "received",
    "date_gte": "2026-09-01",
    "limit": 20,
}):
    print(item["id"])
```

```php tab="PHP"
<?php

use Fiscalisto\Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

foreach ($fiscalisto->satInvoices->list([
    'direction' => 'received',
    'date_gte' => '2026-09-01',
    'limit' => 20,
]) as $item) {
    echo $item['id'], "\n";
}
```

```go tab="Go"
package main

import (
	"context"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// The key comes from FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	for item, err := range client.SatInvoices.ListAutoPaging(ctx, &fiscalisto.ListSatInvoicesParams{
		Direction: fiscalisto.String("received"),
		DateGte:   fiscalisto.String("2026-09-01"),
		Limit:     fiscalisto.Int64(20),
	}) {
		if err != nil {
			log.Fatal(err)
		}
		fmt.Println(item.ID)
	}
}
```

```java tab="Java"
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.model.ListSatInvoicesParams;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

for (var item : fiscalisto.satInvoices().listAutoPaging(new ListSatInvoicesParams()
        .setDirection("received")
        .setDateGte("2026-09-01")
        .setLimit(20))) {
    System.out.println(item.getId());
}
```

```csharp tab="C#"
using Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

await foreach (var item in fiscalisto.SatInvoices.ListAutoPagingAsync(new ListSatInvoicesParams
{
    Direction = "received",
    DateGte = "2026-09-01",
    Limit = 20,
}))
    Console.WriteLine(item.Id);
```

For an RFC of your company (`type: "own"`), the list also carries the invoices the app's automatic download brought, on every plan (Gratis too). Listing invoices, viewing them and downloading their XML or PDF uses no timbres; only requesting a new download from SAT does. `GET /v1/sat_downloads` lists only the downloads the API requested, not the app's automatic ones.

Each invoice (`sat_…`) carries its folio fiscal, who issued it (`issued_by`) and to whom (`issued_to`), the amounts, the transferred and withheld taxes, and its status at SAT (`sat_status`). They're filtered by `direction`, `type`, `counterparty_tax_id`, `date_gte` and `date_lte`, newest to oldest, with the usual [pagination](https://fiscalisto.com/en/docs/api/paginacion). The XML, exactly as SAT delivered it, is at `GET /v1/sat_invoices/{id}/xml`, and its PDF at `GET /v1/sat_invoices/{id}/pdf`: the same one the customer received if it was stamped in Fiscalisto; otherwise, drawn with the issuer's PDF design (a supplier's, with its style and color, never with its logo).

## Withholding certificates

The issuer's withholding and payment information CFDI (what a bank, a platform or whoever paid it withheld, and the certificates it issued) are at `GET /v1/sat_retentions`, as **Facturas › Retenciones** shows them:

```bash tab="cURL"
curl "https://api.fiscalisto.com/v1/sat_retentions?direction=received&year=2025&status=active" \
  -H "Authorization: Bearer $FISCALISTO_API_KEY"
```

```ts tab="TypeScript"
import { Fiscalisto } from "fiscalisto";

// The key comes from FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

for await (const item of fiscalisto.satRetentions.list({
  direction: "received",
  year: 2025,
  status: "active",
})) {
  console.log(item.id);
}
```

```python tab="Python"
from fiscalisto import Fiscalisto

# The key comes from FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

for item in fiscalisto.sat_retentions.list({
    "direction": "received",
    "year": 2025,
    "status": "active",
}):
    print(item["id"])
```

```php tab="PHP"
<?php

use Fiscalisto\Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

foreach ($fiscalisto->satRetentions->list([
    'direction' => 'received',
    'year' => 2025,
    'status' => 'active',
]) as $item) {
    echo $item['id'], "\n";
}
```

```go tab="Go"
package main

import (
	"context"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// The key comes from FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	for item, err := range client.SatRetentions.ListAutoPaging(ctx, &fiscalisto.ListSatRetentionsParams{
		Direction: fiscalisto.String("received"),
		Year:      fiscalisto.Int64(2025),
		Status:    fiscalisto.String("active"),
	}) {
		if err != nil {
			log.Fatal(err)
		}
		fmt.Println(item.ID)
	}
}
```

```java tab="Java"
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.model.ListSatRetentionsParams;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

for (var item : fiscalisto.satRetentions().listAutoPaging(new ListSatRetentionsParams()
        .setDirection("received")
        .setYear(2025)
        .setStatus("active"))) {
    System.out.println(item.getId());
}
```

```csharp tab="C#"
using Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

await foreach (var item in fiscalisto.SatRetentions.ListAutoPagingAsync(new ListSatRetentionsParams
{
    Direction = "received",
    Year = 2025,
    Status = "active",
}))
    Console.WriteLine(item.Id);
```

Each certificate (`srt_…`) carries who withheld (`issued_by`) and from whom (`issued_to`), its key (`code`), the period it covers (`period`), the amounts (`totals`), each tax withheld (`withheld_taxes`) and its `status`: `active` or `canceled`. Received ones SAT reports as cancelled (Fiscalisto checks every month) stay on the list as `canceled`: they no longer count as tax withheld. They're filtered by `direction` (`received` by default or `issued`), `status`, `counterparty_tax_id`, `code` (like `16` interest or `26` platforms), `year` and `month` (the ones covering that month: an annual one from January to December covers all), newest to oldest, with the usual [pagination](https://fiscalisto.com/en/docs/api/paginacion). The XML is at `GET /v1/sat_retentions/{id}/xml` and the PDF at `GET /v1/sat_retentions/{id}/pdf`. The ones you issue through the API are also at [`/v1/retentions`](https://fiscalisto.com/en/docs/api/retenciones), with their stamping.

One the issuer issued (`direction` `issued`) is cancelled with `POST /v1/sat_retentions/{id}/cancel`, also if it was stamped from another system and only came from SAT: `motive` `02` (with errors, or duplicated), `03` (the operation didn't happen) or `01` with `substitution`, the certificate that replaces it (its `srt_…` or its UUID), active, from the same issuer and to the same receiver. It's cancelled at once, with no acceptance, uses no timbres and answers the certificate with `status` `canceled`. One another PAC stamped is cancelled in SAT's portal with the e.firma and the CSD the issuer saved; if one is missing, it answers `cancellation_failed` and says which.

## Limits

Up to 300 downloads a day per account in production and 50 in test mode. In production, requesting one uses a timbre, which covers the first 100 CFDI (if SAT rejects it, the timbre comes back). When SAT says how many it has, every 100 more, or the remainder, use another timbre before downloading them: 1,250 CFDI are 13 timbres. If your account doesn't have enough, the download ends `failed` (event `sat_download.failed`), without downloading anything, and the request's timbre doesn't come back. Free in test mode. See [Limits](https://fiscalisto.com/en/docs/api/limites#what-uses-timbres-without-stamping).

Requesting the same download again (same issuer, dates and filters) while SAT is still working on it returns that same download, without another timbre: that way a retry after a timeout doesn't spend the few identical requests SAT accepts. Once it's finished, an identical one is a new download.
