# The first invoice, in test mode

Use the id of the TEST organization (or an `sk_test_…` key). Nothing here reaches SUNAT.

1. `GET /v1/series` (permission `series:read`): the test twin already has one series for facturas and one for boletas.

2. `POST /v1/invoices/preview` (permission `invoices:emit`): optional: the totals and the number it would take, without issuing.

3. `POST /v1/invoices` (permission `invoices:emit`; `Idempotency-Key` required): one call per invoice. Send a new `Idempotency-Key` per invoice and REUSE it when you retry: the same key with the same body returns the same invoice, never a second one.

```json
{
  "type": "factura",
  "customer": {
    "id_type": "ruc",
    "id_number": "20601188750",
    "name": "CLIENTE S.A.C.",
    "email": "pagos@cliente.example"
  },
  "prices_include_tax": false,
  "items": [
    {
      "description": "Plan Pro (noviembre)",
      "quantity": "1",
      "unit": "ZZ",
      "unit_price": "100.00"
    }
  ],
  "external_ref": "charge_8f3a"
}
```

The answer is `202`: the invoice has its number and is on its way. `status` is `processing` until SUNAT answers; `what_next` says what to do, in words. Amounts are decimal strings; `issue_date` is a Lima wall clock without a zone.

Errors of this call: [`issuer_not_configured`](https://api.invox.page/v1/errors/issuer_not_configured), [`provider_not_connected`](https://api.invox.page/v1/errors/provider_not_connected), [`series_not_found`](https://api.invox.page/v1/errors/series_not_found), [`test_scenario_not_allowed`](https://api.invox.page/v1/errors/test_scenario_not_allowed), [`test_scenario_unknown`](https://api.invox.page/v1/errors/test_scenario_unknown), [`external_ref_already_used`](https://api.invox.page/v1/errors/external_ref_already_used). A request that fails validation ([`validation_failed`](https://api.invox.page/v1/errors/validation_failed)) lists EVERY problem in `errors` and does not consume the key.

To choose what the simulated provider answers, send the header `Test-Scenario: <name>` (see [test mode](https://api.invox.page/v1/docs/test-mode)).

Next: [follow it to its outcome](https://api.invox.page/v1/docs/follow-invoice).
