# Invoice batches

> Stamp up to 1,000 invoices of one issuer with a single request, all checked before starting.

A batch is for what's invoiced all at once: a condominium's monthly fees, tuition, a marketplace's sales of the day. Instead of a thousand requests and their limits, you send one.

Payroll receipts have their own batch: see [Stamp the whole payroll at once](https://fiscalisto.com/en/docs/api/nomina#stamp-the-whole-payroll-at-once).

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/invoice_batches \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Idempotency-Key: cuotas-2026-10" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Cuotas de octubre",
    "invoices": [
      {
        "reference": "depto-101",
        "customer": "cus_OufpKqnrvx9p1",
        "payment_form": "03",
        "items": [{ "product": "prd_OufpKqnrvx9p1" }]
      },
      {
        "reference": "depto-102",
        "customer": { "tax_id": "ICV060329BY0", "legal_name": "INMOBILIARIA CVA", "tax_system": "601", "zip": "33826" },
        "payment_form": "03",
        "items": [{ "description": "Cuota de mantenimiento", "product_key": "80131500", "unit_price": 1500 }]
      }
    ]
  }'
```

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

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

const invoiceBatch = await fiscalisto.invoiceBatches.create({
  name: "Cuotas de octubre",
  invoices: [
    {
      reference: "depto-101",
      customer: "cus_OufpKqnrvx9p1",
      payment_form: "03",
      items: [{ product: "prd_OufpKqnrvx9p1" }],
    },
    {
      reference: "depto-102",
      customer: {
        tax_id: "ICV060329BY0",
        legal_name: "INMOBILIARIA CVA",
        tax_system: "601",
        zip: "33826",
      },
      payment_form: "03",
      items: [
        {
          description: "Cuota de mantenimiento",
          product_key: "80131500",
          unit_price: 1500,
        },
      ],
    },
  ],
}, { idempotencyKey: "cuotas-2026-10" });
```

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

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

invoice_batch = fiscalisto.invoice_batches.create({
    "name": "Cuotas de octubre",
    "invoices": [
        {
            "reference": "depto-101",
            "customer": "cus_OufpKqnrvx9p1",
            "payment_form": "03",
            "items": [{"product": "prd_OufpKqnrvx9p1"}],
        },
        {
            "reference": "depto-102",
            "customer": {
                "tax_id": "ICV060329BY0",
                "legal_name": "INMOBILIARIA CVA",
                "tax_system": "601",
                "zip": "33826",
            },
            "payment_form": "03",
            "items": [
                {
                    "description": "Cuota de mantenimiento",
                    "product_key": "80131500",
                    "unit_price": 1500,
                },
            ],
        },
    ],
}, idempotency_key="cuotas-2026-10")
```

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

use Fiscalisto\Fiscalisto;

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

$invoiceBatch = $fiscalisto->invoiceBatches->create([
    'name' => 'Cuotas de octubre',
    'invoices' => [
        [
            'reference' => 'depto-101',
            'customer' => 'cus_OufpKqnrvx9p1',
            'payment_form' => '03',
            'items' => [['product' => 'prd_OufpKqnrvx9p1']],
        ],
        [
            'reference' => 'depto-102',
            'customer' => [
                'tax_id' => 'ICV060329BY0',
                'legal_name' => 'INMOBILIARIA CVA',
                'tax_system' => '601',
                'zip' => '33826',
            ],
            'payment_form' => '03',
            'items' => [
                [
                    'description' => 'Cuota de mantenimiento',
                    'product_key' => '80131500',
                    'unit_price' => 1500,
                ],
            ],
        ],
    ],
], ['idempotency_key' => 'cuotas-2026-10']);
```

```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()

	invoiceBatch, err := client.InvoiceBatches.Create(ctx, &fiscalisto.CreateInvoiceBatchParams{
		Name: fiscalisto.String("Cuotas de octubre"),
		Invoices: []fiscalisto.CreateInvoiceBatchParamsInvoice{
			{
				Reference:   fiscalisto.String("depto-101"),
				Customer:    fiscalisto.IDOf[fiscalisto.InvoiceCreateCustomer]("cus_OufpKqnrvx9p1"),
				PaymentForm: fiscalisto.String("03"),
				Items: []fiscalisto.InvoiceCreateItem{
					{Product: fiscalisto.String("prd_OufpKqnrvx9p1")},
				},
			},
			{
				Reference: fiscalisto.String("depto-102"),
				Customer: fiscalisto.ObjectOf(fiscalisto.InvoiceCreateCustomer{
					TaxID:     "ICV060329BY0",
					LegalName: "INMOBILIARIA CVA",
					TaxSystem: "601",
					Zip:       "33826",
				}),
				PaymentForm: fiscalisto.String("03"),
				Items: []fiscalisto.InvoiceCreateItem{
					{
						Description: fiscalisto.String("Cuota de mantenimiento"),
						ProductKey:  fiscalisto.String("80131500"),
						UnitPrice:   fiscalisto.Float64(1500),
					},
				},
			},
		},
	}, fiscalisto.WithIdempotencyKey("cuotas-2026-10"))
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(invoiceBatch.ID)
}
```

```java tab="Java"
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.RequestOptions;
import com.fiscalisto.model.CreateInvoiceBatchParams;
import com.fiscalisto.model.CreateInvoiceBatchParamsInvoice;
import com.fiscalisto.model.InvoiceCreateCustomer;
import com.fiscalisto.model.InvoiceCreateItem;
import java.util.List;

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

var invoiceBatch = fiscalisto.invoiceBatches().create(new CreateInvoiceBatchParams()
        .setName("Cuotas de octubre")
        .setInvoices(List.of(
                new CreateInvoiceBatchParamsInvoice()
                        .setReference("depto-101")
                        .setCustomer("cus_OufpKqnrvx9p1")
                        .setPaymentForm("03")
                        .setItems(List.of(
                                new InvoiceCreateItem()
                                        .setProduct("prd_OufpKqnrvx9p1")
                        )),
                new CreateInvoiceBatchParamsInvoice()
                        .setReference("depto-102")
                        .setCustomer(new InvoiceCreateCustomer()
                                .setTaxId("ICV060329BY0")
                                .setLegalName("INMOBILIARIA CVA")
                                .setTaxSystem("601")
                                .setZip("33826"))
                        .setPaymentForm("03")
                        .setItems(List.of(
                                new InvoiceCreateItem()
                                        .setDescription("Cuota de mantenimiento")
                                        .setProductKey("80131500")
                                        .setUnitPrice(1500)
                        ))
        )), RequestOptions.idempotencyKey("cuotas-2026-10"));
System.out.println(invoiceBatch.getId());
```

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

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

var invoiceBatch = await fiscalisto.InvoiceBatches.CreateAsync(new CreateInvoiceBatchParams
{
    Name = "Cuotas de octubre",
    Invoices = new()
    {
        new()
        {
            Reference = "depto-101",
            Customer = "cus_OufpKqnrvx9p1",
            PaymentForm = "03",
            Items = new()
            {
                new() { Product = "prd_OufpKqnrvx9p1" },
            },
        },
        new()
        {
            Reference = "depto-102",
            Customer = new InvoiceCreateCustomer
            {
                TaxId = "ICV060329BY0",
                LegalName = "INMOBILIARIA CVA",
                TaxSystem = "601",
                Zip = "33826",
            },
            PaymentForm = "03",
            Items = new()
            {
                new()
                {
                    Description = "Cuota de mantenimiento",
                    ProductKey = "80131500",
                    UnitPrice = 1500,
                },
            },
        },
    },
}, new RequestOptions { IdempotencyKey = "cuotas-2026-10" });
```

Each invoice in the batch is the same body as [`POST /v1/invoices`](https://fiscalisto.com/en/docs/api/referencia/facturas/create-invoice), without `issuer` (the batch belongs to one issuer), without `type` or `global` (they're income invoices) and with `reference` instead of `metadata`: your identifier for that invoice, which comes back in the result.

## How it's stamped

1. **They're all checked before starting.** If one fails the check, the API returns `422` `batch_invalid` with `param` set to the invoice and field (`invoices.3.items.0.unit_price`) and none is stamped. Correct it and send the batch again.
2. **It answers `202` right away**, with the batch in `status: "processing"`. Each invoice that has warnings carries them in `invoices[].warnings`, the same `POST /v1/invoices` would give (a customer on SAT's lists, a lease without property tax account, withholdings that won't be stamped): it's stamped as you sent it. They come only in this answer (and when you repeat it with the same `Idempotency-Key`), not in `GET`.
3. **They're stamped in the background**, at the speed the PAC allows. Each stamped invoice sends its `invoice.stamped`, like any other.
4. **When done**, `invoice_batch.completed` arrives and the batch becomes `completed`, with how many were stamped (`stamped`) and how many weren't (`failed`).

```json
{
  "id": "bat_OufpKqnrvx9p4hMdcoapAo5aaGJEme7mXj",
  "object": "invoice_batch",
  "status": "completed",
  "total": 2,
  "stamped": 1,
  "failed": 1,
  "processing": 0,
  "invoices": [
    { "index": 0, "reference": "depto-101", "status": "valid", "invoice": "inv_OufpKqnrvx9p0mn7VjQ6JlfipKAkHWstOK", "uuid": "DB494B07-D6DE-4F70-8ED0-C8B864FF8717", "total": 1740, "error": null },
    { "index": 1, "reference": "depto-102", "status": "failed", "invoice": null, "uuid": null, "total": 1740, "error": "El SAT no reconoce el nombre del cliente. Escríbalo letra por letra como en su constancia de situación fiscal: completo, con o sin acentos según venga ahí, y sin «S.A. de C.V.» ni otro régimen de capital." }
  ]
}
```

An invoice can fail even though it passed the check, if SAT rejects it (almost always because of the customer's data). Those don't use a timbre: correct them and stamp each one with `POST /v1/invoices`.

## Check the progress

[`GET /v1/invoice_batches/{id}`](https://fiscalisto.com/en/docs/api/referencia/lotes/get-invoice-batch) says how many are done and each one's status. If you don't use webhooks, check it every few seconds until it says `completed`.

## Timbres

Each stamped invoice uses a timbre, when it's stamped. Before sending a large batch check you have enough with [`GET /v1/balance`](https://fiscalisto.com/en/docs/api/referencia/cuenta/get-balance): if they run out halfway, the remaining ones end `failed` with the reason in `error`. After buying, send them in another batch, with another `Idempotency-Key`.

## Repeat it

Sending the same batch with the same `Idempotency-Key` returns the batch that already exists (`202`, like the first time, with `idempotent-replayed: true`), without stamping anything again.
