# Invoicing API

> Stamp CFDI 4.0 from your system with one call: invoices, payments, credit notes, payroll and withholdings, with Fiscalisto's SAT checks.

Fiscalisto's API stamps Mexican electronic invoices (CFDI 4.0) from your server. You send the invoice's data as JSON; Fiscalisto fills in what has a usual value, checks SAT's rules before spending a timbre, seals it with the issuer's certificate, has an authorized PAC stamp it, and answers with the stamped invoice, its UUID, the PDF and the XML.

Field names are in English, as in any API (`customer`, `items`, `unit_price`). These guides are also [in Spanish](https://fiscalisto.com/docs/api); error messages come in English when you send `Accept-Language: en`. The [API reference](https://fiscalisto.com/en/docs/api/referencia/facturas/create-invoice) is in Spanish, generated from the OpenAPI document.

## Your first invoice in a minute

1. In Fiscalisto, open **Desarrolladores** (Developers) in your company's menu (every company has the API). The first time, you get a test key that starts with `fk_test_` and a test issuer ready to stamp. No account yet? [Create one](/signup?callbackUrl=%2Fempresas%3Fnueva%3Dapi): you land straight in **Desarrolladores** with your key.
2. Keep the key in an environment variable on your server:

```bash
export FISCALISTO_API_KEY="fk_test_..."
```

3. Stamp an invoice:

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/invoices \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Idempotency-Key: pedido-A-1042" \
  -H "Content-Type: application/json" \
  -d '{
    "customer": {
      "tax_id": "ICV060329BY0",
      "legal_name": "INMOBILIARIA CVA",
      "tax_system": "601",
      "zip": "33826"
    },
    "payment_form": "03",
    "items": [
      { "description": "Mensualidad", "product_key": "86121700", "quantity": 2, "unit_price": 2500 }
    ]
  }'
```

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

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

const invoice = await fiscalisto.invoices.create({
  customer: {
    tax_id: "ICV060329BY0",
    legal_name: "INMOBILIARIA CVA",
    tax_system: "601",
    zip: "33826",
  },
  payment_form: "03",
  items: [
    {
      description: "Mensualidad",
      product_key: "86121700",
      quantity: 2,
      unit_price: 2500,
    },
  ],
}, { idempotencyKey: "pedido-A-1042" });
```

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

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

invoice = fiscalisto.invoices.create({
    "customer": {
        "tax_id": "ICV060329BY0",
        "legal_name": "INMOBILIARIA CVA",
        "tax_system": "601",
        "zip": "33826",
    },
    "payment_form": "03",
    "items": [
        {
            "description": "Mensualidad",
            "product_key": "86121700",
            "quantity": 2,
            "unit_price": 2500,
        },
    ],
}, idempotency_key="pedido-A-1042")
```

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

use Fiscalisto\Fiscalisto;

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

$invoice = $fiscalisto->invoices->create([
    'customer' => [
        'tax_id' => 'ICV060329BY0',
        'legal_name' => 'INMOBILIARIA CVA',
        'tax_system' => '601',
        'zip' => '33826',
    ],
    'payment_form' => '03',
    'items' => [
        [
            'description' => 'Mensualidad',
            'product_key' => '86121700',
            'quantity' => 2,
            'unit_price' => 2500,
        ],
    ],
], ['idempotency_key' => 'pedido-A-1042']);
```

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

	invoice, err := client.Invoices.Create(ctx, &fiscalisto.InvoiceCreate{
		Customer: fiscalisto.ObjectOf(fiscalisto.InvoiceCreateCustomer{
			TaxID:     "ICV060329BY0",
			LegalName: "INMOBILIARIA CVA",
			TaxSystem: "601",
			Zip:       "33826",
		}),
		PaymentForm: fiscalisto.String("03"),
		Items: []fiscalisto.InvoiceCreateItem{
			{
				Description: fiscalisto.String("Mensualidad"),
				ProductKey:  fiscalisto.String("86121700"),
				Quantity:    fiscalisto.Float64(2),
				UnitPrice:   fiscalisto.Float64(2500),
			},
		},
	}, fiscalisto.WithIdempotencyKey("pedido-A-1042"))
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(invoice.ID)
}
```

```java tab="Java"
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.RequestOptions;
import com.fiscalisto.model.InvoiceCreate;
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 invoice = fiscalisto.invoices().create(new InvoiceCreate()
        .setCustomer(new InvoiceCreateCustomer()
                .setTaxId("ICV060329BY0")
                .setLegalName("INMOBILIARIA CVA")
                .setTaxSystem("601")
                .setZip("33826"))
        .setPaymentForm("03")
        .setItems(List.of(
                new InvoiceCreateItem()
                        .setDescription("Mensualidad")
                        .setProductKey("86121700")
                        .setQuantity(2)
                        .setUnitPrice(2500)
        )), RequestOptions.idempotencyKey("pedido-A-1042"));
System.out.println(invoice.getId());
```

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

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

var invoice = await fiscalisto.Invoices.CreateAsync(new InvoiceCreate
{
    Customer = new InvoiceCreateCustomer
    {
        TaxId = "ICV060329BY0",
        LegalName = "INMOBILIARIA CVA",
        TaxSystem = "601",
        Zip = "33826",
    },
    PaymentForm = "03",
    Items = new()
    {
        new()
        {
            Description = "Mensualidad",
            ProductKey = "86121700",
            Quantity = 2,
            UnitPrice = 2500,
        },
    },
}, new RequestOptions { IdempotencyKey = "pedido-A-1042" });
```

The answer is the stamped invoice (`201`):

```json
{
  "id": "inv_OufpKqnrvx9p0Nfbydl9jG4UNGeTYcvdrg",
  "object": "invoice",
  "livemode": false,
  "status": "valid",
  "uuid": "5F1E8C2A-3B7D-4C9E-A1B2-C3D4E5F60718",
  "folio": "1",
  "subtotal": 5000,
  "taxes": { "iva": 800, "ieps": 0, "iva_withheld": 0, "isr_withheld": 0, "local_transferred": 0, "local_withheld": 0 },
  "total": 5800,
  "...": "..."
}
```

4. Download the PDF or the XML:

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/invoices/inv_OufpKqnrvx9p0Nfbydl9jG4UNGeTYcvdrg/pdf \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" -o factura.pdf
```

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

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

await writeFile("factura.pdf", await fiscalisto.invoices.pdf("inv_OufpKqnrvx9p0Nfbydl9jG4UNGeTYcvdrg"));
```

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

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

with open("factura.pdf", "wb") as f:
    f.write(fiscalisto.invoices.pdf("inv_OufpKqnrvx9p0Nfbydl9jG4UNGeTYcvdrg"))
```

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

use Fiscalisto\Fiscalisto;

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

file_put_contents('factura.pdf', $fiscalisto->invoices->pdf('inv_OufpKqnrvx9p0Nfbydl9jG4UNGeTYcvdrg'));
```

```go tab="Go"
package main

import (
	"context"
	"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()

	pdf, err := client.Invoices.PDF(ctx, "inv_OufpKqnrvx9p0Nfbydl9jG4UNGeTYcvdrg", nil)
	if err != nil {
		log.Fatal(err)
	}
	if err := os.WriteFile("factura.pdf", pdf, 0o644); err != nil {
		log.Fatal(err)
	}
}
```

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

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

Files.write(Path.of("factura.pdf"), fiscalisto.invoices().pdf("inv_OufpKqnrvx9p0Nfbydl9jG4UNGeTYcvdrg"));
```

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

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

await File.WriteAllBytesAsync("factura.pdf", await fiscalisto.Invoices.PdfAsync("inv_OufpKqnrvx9p0Nfbydl9jG4UNGeTYcvdrg"));
```

You didn't send the CFDI use, the payment method, the currency, the unit, the tax object or the IVA: they take their usual values (use G03, PUE, MXN, unit E48, or H87 for a good, object 02, IVA 16%). Send only what changes.

With TypeScript, Python, PHP, Go, Java or C#, the [SDKs](https://fiscalisto.com/en/docs/api/sdk) give you types for every field and the `Idempotency-Key` without thinking about it:

```ts
import { Fiscalisto } from "fiscalisto";

const fiscalisto = new Fiscalisto(process.env.FISCALISTO_API_KEY);
const invoice = await fiscalisto.invoices.create({ customer, payment_form: "03", items });
```

## What you need to know

- **Test and live.** `fk_test_` keys stamp for free in SAT's test environment; `fk_live_` keys stamp real CFDI and use one timbre each. See [Test and live](https://fiscalisto.com/en/docs/api/pruebas-y-produccion).
- **Idempotency-Key.** Everything that stamps requires one. If the answer gets lost, repeat the request with the same key: nothing is ever stamped twice. See [Idempotency](https://fiscalisto.com/en/docs/api/idempotencia).
- **Clear errors.** Every error says which field to fix (`param`), how (`message`) and, if SAT rejected it, its code (`sat_code`). See [Errors](https://fiscalisto.com/en/docs/api/errores).
- **Webhooks.** Cancellations the customer accepts days later, invoices the PAC took a while to stamp and batches reach you as signed events. See [Webhooks](https://fiscalisto.com/en/docs/api/webhooks).

## What you can stamp

| Document | Route |
| --- | --- |
| Income, global or transfer invoice (with complementos) | [`POST /v1/invoices`](https://fiscalisto.com/en/docs/api/referencia/facturas/create-invoice) |
| Payment complement (type P) | [`POST /v1/payments`](https://fiscalisto.com/en/docs/api/referencia/pagos-y-notas-de-credito/create-payment) |
| Credit note (type E) | [`POST /v1/credit_notes`](https://fiscalisto.com/en/docs/api/referencia/pagos-y-notas-de-credito/create-credit-note) |
| Advance payment and its application | [`POST /v1/advances`](https://fiscalisto.com/en/docs/api/referencia/anticipos/create-advance) |
| Payroll receipt (type N) | [`POST /v1/payroll_receipts`](https://fiscalisto.com/en/docs/api/referencia/nomina/create-payroll-receipt) |
| Withholding certificate (retenciones) | [`POST /v1/retentions`](https://fiscalisto.com/en/docs/api/referencia/retenciones/create-retention) |
| Up to 1,000 invoices at once | [`POST /v1/invoice_batches`](https://fiscalisto.com/en/docs/api/referencia/lotes/create-invoice-batch) |
| A whole payroll at once | [`POST /v1/payroll_batches`](https://fiscalisto.com/en/docs/api/referencia/nomina/create-payroll-batch) |

## For agents and tools

- To have a coding agent (Claude Code, Cursor, Codex…) integrate Fiscalisto, connect this documentation's MCP server and give it the one-page guide: see [Fiscalisto for AI agents](https://fiscalisto.com/en/docs/api/agentes).
- The complete OpenAPI 3.1 document is at [`https://api.fiscalisto.com/v1/openapi.json`](https://api.fiscalisto.com/v1/openapi.json), no key needed. Every field has its description and its name in SAT's XML.
- Every page of the Spanish guides is also in Markdown: add `.md` to its address (for example [`/docs/api/idempotencia.md`](https://fiscalisto.com/docs/api/idempotencia.md)).
- [`/docs/api/llms.txt`](https://fiscalisto.com/docs/api/llms.txt) indexes every page, and [`/docs/api/llms-full.txt`](https://fiscalisto.com/docs/api/llms-full.txt) has the whole guides in one file.
