# CLI: invoicing from your terminal

> Sign in through the browser, set up the SDK in your project, stamp, cancel and receive webhooks on your computer with a single command. With --json, for agents and scripts.

Fiscalisto's CLI comes in the `fiscalisto` npm package. There's nothing to install: run `npx fiscalisto` on any computer with Node 20 or newer.

```bash
npx fiscalisto login     # se abre el navegador; autorice y vuelva
npx fiscalisto init      # SDK, llave en .env y un ejemplo que timbra
node --env-file=.env fiscalisto-ejemplo.mjs
```

In those three steps your project already stamps in test: without copying keys or reading the reference first.

## Signing in

`fiscalisto login` shows you a code and opens `fiscalisto.com/cli`. There, with the company open, check that the code is the same as in your terminal and press **Autorizar** (Authorize). The CLI gets a new test key, named after your computer («CLI · mi-mac»), and keeps it in `~/.config/fiscalisto/config.json`, which only you can read.

| Command | What it does |
| --- | --- |
| `fiscalisto login` | Test key through the browser |
| `fiscalisto login --live` | Also asks for a live one; needs two-step verification |
| `fiscalisto login --key fk_test_…` | Keeps a key you already have, without a browser (servers, CI) |
| `fiscalisto whoami` | Account, mode, timbres and issuers |
| `fiscalisto logout` | Forgets the keys on this computer |

The CLI's keys show in **Desarrolladores › Llaves** like any other: revoke them there whenever you want. The browser code expires in 10 minutes and works once.

The CLI uses, in this order: `--api-key`, the `FISCALISTO_API_KEY` variable and the saved key. With `--live` it uses the saved live key and asks before stamping (`--yes` doesn't ask).

## Setting up your project

`fiscalisto init` recognizes your project (`package.json`, `pyproject.toml` or `requirements.txt`, `composer.json`, `go.mod`, `pom.xml` or `build.gradle`, a `.csproj`) and:

1. Puts `FISCALISTO_API_KEY` in `.env` and adds `.env` to `.gitignore`.
2. Installs the [SDK](https://fiscalisto.com/en/docs/api/sdk) with your package manager (npm, pnpm, yarn, bun, pip, uv, poetry, composer, `go get` or `dotnet add package`) and records it in your dependencies (with pip, in `requirements.txt`). In Java it tells you which dependency to add to your `pom.xml` or `build.gradle`.
3. Writes an example that stamps a test invoice and tells you how to run it.

`--lang node|python|php|go|dotnet|java` picks the language, `--no-install` installs nothing, and `--agents` adds a how-to-invoice section to your `AGENTS.md` (or `CLAUDE.md`) and leaves the complete guide in `.claude/skills/fiscalisto/SKILL.md`, so your coding agent uses the SDK, idempotency and the [test RFCs](https://fiscalisto.com/en/docs/api/pruebas-y-produccion#trigger-each-sat-rejection) without you explaining it. See [Fiscalisto for AI agents](https://fiscalisto.com/en/docs/api/agentes).

## Invoices

```bash
fiscalisto invoices create --example                      # una factura de prueba
fiscalisto invoices create --customer ICV060329BY0 --name "INMOBILIARIA CVA" \
  --regime 601 --zip 33826 --item "Consultoría|80101500|1000"
fiscalisto invoices create --data @factura.json           # el mismo cuerpo que POST /v1/invoices
fiscalisto invoices list --status valid --customer ICV060329BY0
fiscalisto invoices get inv_…
fiscalisto invoices pdf inv_… -o factura.pdf              # también xml; sin -o, inv_….pdf
fiscalisto invoices send inv_… --to cliente@empresa.mx
fiscalisto invoices cancel inv_… --motive 02
```

Each `create` carries an [Idempotency-Key](https://fiscalisto.com/en/docs/api/idempotencia): if the connection drops and you repeat it with `--idempotency-key`, nothing is stamped twice. A SAT rejection shows with its code and its explanation, as in the API.

`fiscalisto sat-lists check RFC [RFC…]` checks one or several RFCs on [SAT's lists](https://fiscalisto.com/en/docs/api/listas-del-sat).

## Webhooks on your computer

```bash
fiscalisto listen --forward-to http://localhost:3000/webhooks
```

`listen` follows your account's events and sends them to your local server, signed just like real [webhooks](https://fiscalisto.com/en/docs/api/webhooks) (`webhook-id`, `webhook-timestamp`, `webhook-signature`). The signature uses a secret of this computer, which the CLI shows when it starts and is always the same: put it in your app's `FISCALISTO_WEBHOOK_SECRET` and your verification works unchanged. With `--events invoice.stamped,invoice.failed` it only forwards those. If your server doesn't answer (you're restarting it), `listen` retries every 3 seconds for up to a minute, in order, and skips no events. What `listen` reads every 2 seconds doesn't fill **Solicitudes** or the **Uso** chart.

In another terminal, trigger the event you want to test:

| Command | What happens in test |
| --- | --- |
| `fiscalisto trigger invoice.stamped` | Stamps a test invoice |
| `fiscalisto trigger invoice.failed` | SAT rejects it (with the test RFC `NOM010101FK9`) |
| `fiscalisto trigger invoice.canceled` | Stamps one and cancels it |
| `fiscalisto trigger invoice_batch.completed` | A batch of two invoices |

`trigger` only works with test keys. To send any other event to an endpoint, without stamping, use `fiscalisto webhooks test whe_… --type invoice.paid` (it's [**Mandar evento de prueba**](https://fiscalisto.com/en/docs/api/webhooks#a-test-event-without-stamping)). `fiscalisto webhooks list|create|delete` and `fiscalisto events list|get` do the same as the dashboard, and `fiscalisto webhooks recover whe_… --since 24h` (or `7d`, or an ISO 8601 date) sends again everything a webhook didn't receive, like [**Reenviar fallidas**](https://fiscalisto.com/en/docs/api/webhooks#recovering-everything-that-didnt-arrive).

## Any API route

```bash
fiscalisto api /v1/account
fiscalisto api POST /v1/customers --data '{"tax_id":"ICV060329BY0","legal_name":"INMOBILIARIA CVA","tax_system":"601","zip":"33826"}'
fiscalisto api /v1/invoices/inv_…/pdf > factura.pdf
```

`fiscalisto issuers list` shows your issuers and `fiscalisto issuers get iss_…` one with its status. `api` calls any route of the [reference](https://fiscalisto.com/en/docs/api/referencia/facturas/create-invoice) with your key. `--data` takes JSON, `@file.json` or `-` (reads it from standard input).

## The API without internet

`fiscalisto mock` starts a server on your computer that answers every route like the API, with the same shape for each object and each error, without internet or a real key. It's for developing on a plane and for your project's tests (in CI, without network).

```bash
npx fiscalisto mock --port 12111
```

- It accepts any `fk_test_` key (`fk_test_mock`).
- What it creates stays in memory while it runs: a created customer can be read, listed, changed and deleted. An invoice is created `valid`, with its sample PDF and XML.
- Repeating a `POST` with the same `Idempotency-Key` answers the same, like the API.
- It doesn't check SAT's rules or stamp. Before going live, test against the API with your `fk_test_` key (test mode is free).

Point your SDK at it with the API's address: `baseUrl` in TypeScript, `base_url` in Python and PHP, `WithBaseURL` in Go, `.baseUrl` in Java and `BaseUrl` in .NET. In Node tests, without opening a port:

```ts
import { Fiscalisto } from "fiscalisto";
import { createMock } from "fiscalisto/mock";

const mock = createMock();
const fiscalisto = new Fiscalisto("fk_test_mock", {
  baseUrl: "http://mock",
  fetch: (url, init) => mock.fetch(new Request(url, init)),
});
```

## For agents and scripts

With `--json` every command answers a single JSON (and `listen` one line per event), errors included: `{"error": {"type", "code", "message", "param"}}`, the same as the API's. The CLI exits with code 0 if everything went well, 2 if the command is mistyped and 1 on any other error.

```bash
fiscalisto invoices create --example --json | jq -r .uuid
```

### The documentation in your agent

Add the documentation as an MCP server and your coding agent looks things up while it codes (`get_started`, `search_docs`, `get_page`, `list_pages`), no key needed:

```bash
claude mcp add --transport http fiscalisto-docs https://fiscalisto.com/docs/api/mcp
```

Besides searching and reading the guides (`search_docs`, `get_page`, `list_pages`), the server explores the API reference:

| Tool | What it does |
| --- | --- |
| `get_started` | The complete integration guide on one page ([SKILL.md](https://fiscalisto.com/docs/api/SKILL.md)). |
| `list_operations` | Every operation with its `operationId`, method and path, by section (`tag`). |
| `describe_operation` | An operation by its `operationId`, its SDK method (`invoices.create`), «POST /v1/invoices» or in words («create invoice»): parameters, every field of the body and the answer, examples and the code with the SDK of the `language` you pick (`ts`, `python`, `php`, `csharp`, `go`, `java`). |
| `describe_object` | An object's fields (`Invoice`, `Event`…) with an example. |
| `explain_error` | What an `error.code` means and how to fix it. |
| `call_api` | Tries a real request in test mode with your `fk_test_` key (`api_key`) and returns the status, the `Request-Id` and the JSON. It never accepts an `fk_live_`. |

So your agent can read the route, build the body, try it against your test mode and fix it with the error before writing the code. The request shows in **Desarrolladores › Solicitudes** with the key it used.

In Cursor, Codex, VS Code or another client, use the same address as an HTTP MCP server ([how, in each one](https://fiscalisto.com/en/docs/api/agentes#connecting-the-documentation-mcp)). Every page also has **Copiar como Markdown**, **Abrir en ChatGPT**, **Abrir en Claude**, **Abrir en Cursor** and **Conectar su agente** above the title.

`fiscalisto docs` prints the integration guide for agents (the same as [SKILL.md](https://fiscalisto.com/docs/api/SKILL.md) and `get_started`, without internet) with the link to the [llms.txt](https://fiscalisto.com/docs/api/llms.txt) index, and `fiscalisto open llaves` (or `panel`, `facturas`, `webhooks`, `eventos`, `docs`) opens that dashboard page.
