# TicketBAI and Verifactu REST API documentation

With the Ticketbai WS REST API you connect your application, online store, POS or ERP to the Basque provincial tax authorities (TicketBAI in Araba, Bizkaia/Batuz and Gipuzkoa) and to the AEAT (Spanish Tax Agency) for Verifactu, and you generate FacturaE electronic invoices for public administrations.

**Just getting started?**

- [Quick start guide](https://ticketbaiws.eus/es/desarrolladores/guia-rapida/): from zero to your first invoice in production.
- [Examples](https://ticketbaiws.eus/es/desarrolladores/ejemplos/): 22 ready-to-copy cases (simplified, intra-EU, corrective invoices…).
- [Test console](https://ticketbaiws.eus/es/desarrolladores/terminal/): try the API without creating an account.
- [Service status](https://ticketbaiws.eus/es/desarrolladores/estado/): response times of the API and of each tax authority.

## Environments and base URL

All methods follow this pattern:

https://{entorno}.ticketbaiws.eus/{recurso}/

- `POST`  Create (e.g. a new invoice)
- `GET`  Retrieve
- `PUT`  Update
- `DEL`  Cancel

The environment is **api-test**  for testing (submissions go to the tax authority's test environment and have no tax validity) and **api**  for production. Some management methods (companies, licenses and NIF validation) only exist in production. [Webhooks](https://ticketbaiws.eus/en/webhooks-post/) work in both environments and are configured separately in each one.

## Authentication

Every request carries two headers: **Token** , the company's token for that environment (you'll find it in the private area; there is one for test and another for production), and **Nif** , the issuer's NIF (Spanish tax ID). Parameters are sent in a `JSON`  object with `Content-Type: application/json`. For GET methods you can also send them in the query string.

Exception: the [companies](https://ticketbaiws.eus/en/empresas-post/) and [licenses](https://ticketbaiws.eus/en/licencias-post/) methods manage your account and authenticate with the **developer token**  of your customer account and the account's NIF, not with those of a company.

## Results and responses

The API responds with HTTP 200 and an object with three variables: **result** , **return**  and **msg** .

- **result** : `OK`, `PENDING` (accepted and pending submission to the tax authority) or `ERROR`.
- **return** : the resulting data (fingerprint, verification URL, QR code…).
- **msg** : status or error messages.

Always check **result** , not just the HTTP status code.

## Submission to the tax authority

The API responds immediately and the submission to the tax authority is done in the background. To find out how it ended, retrieve the invoice with [GET /tbai/](https://ticketbaiws.eus/en/ticketbai-get/) or set up a [webhook](https://ticketbaiws.eus/en/webhooks-post/). If you need the tax authority's response in the same request, send `"sincrono": true` in [POST /tbai/](https://ticketbaiws.eus/en/ticketbai-post/). Line amounts are **excluding VAT** .

## Rate limits

If the request limit is exceeded, the API responds with HTTP 429. Retry with increasing backoff and don't poll the status in a loop: that's what webhooks are for.

## For AI agents and code generators

- [OpenAPI 3.1 specification](https://api.ticketbaiws.eus/openapi.json) for all methods.
- [llms.txt](https://ticketbaiws.eus/llms.txt) and [llms-full.txt](https://ticketbaiws.eus/llms-full.txt) (the whole documentation in one file).
- Every page of this documentation has a Markdown version: add `.md` to the URL, e.g. [en/ticketbai-post.md](https://ticketbaiws.eus/en/ticketbai-post.md).

**GET** `https://{entorno}.ticketbaiws.eus/status/`

```bash
$ curl --request GET \
     --url https://api-test.ticketbaiws.eus/status/ \
     --header 'Accept: application/json' \
     --header 'Content-Type: application/json' \
     --header 'Token: xxx' \
     --header 'Nif: 00000014Z'
```

Respuesta:

```json
HTTP/1.1 200 OK
{
	"result": "OK",
	"return": null,
	"msg": "Ready"
}
```

Response (error):

```json
HTTP/1.1 200 OK
{
	"result": "ERROR",
	"return": null,
	"msg": "License expired"
}
```

## API methods

### TicketBAI / Verifactu methods

- [`POST`  New invoice / resubmission (zuzendu) TicketBAI / Verifactu](https://ticketbaiws.eus/en/ticketbai-post/)
- [`POST`  Complete a simplified invoice](https://ticketbaiws.eus/en/tbai-completar-post/)
- [`GET`  Get a TicketBAI / Verifactu invoice](https://ticketbaiws.eus/en/ticketbai-get/)
- [`GET`  List TicketBAI / Verifactu invoices](https://ticketbaiws.eus/en/ticketbai-list-get/)
- [`GET`  Download TicketBAI / Verifactu XML](https://ticketbaiws.eus/en/ticketbai-xml-get/)
- [`GET`  Download invoice in FacturaE format](https://ticketbaiws.eus/en/facturae-get/)
- [`GET`  Download invoice as PDF](https://ticketbaiws.eus/en/tbai-pdf-get/)
- [`GET`  System status](https://ticketbaiws.eus/en/status-get/)
- [`DEL`  Cancel a TicketBAI / Verifactu invoice](https://ticketbaiws.eus/en/ticketbai-del/)
- [`PUT`  Force TicketBAI / Verifactu resend](https://ticketbaiws.eus/en/reset-tbai-put/)
- [`POST`  Validate a NIF with the AEAT](https://ticketbaiws.eus/en/validar-nif-post/)
- [`POST`  Validate a VAT number in VIES](https://ticketbaiws.eus/en/validar-nif-vies-post/)

### Representation document

- [`GET`  Representation document - Download template](https://ticketbaiws.eus/en/doc-representante-modelo-get/)
- [`POST`  Representation document - Upload document](https://ticketbaiws.eus/en/doc-representante-post/)
- [`GET`  Representation document - Download uploaded document](https://ticketbaiws.eus/en/doc-representante-get/)
- [`DELETE`  Representation document - Revoke uploaded document](https://ticketbaiws.eus/en/doc-representante-delete/)

### BATUZ BIZKAIA specific methods

- [`GET`  List IAE activity codes](https://ticketbaiws.eus/en/epigrafes-get/)
- [`POST`  LROE - **Received invoices**  - Submit (BATUZ)](https://ticketbaiws.eus/en/lroe-recibidas-post/)
- [`PUT`  LROE - **Received invoices**  - Update (BATUZ)](https://ticketbaiws.eus/en/lroe-recibidas-put/)
- [`GET`  LROE - **Received invoices**  - Query (BATUZ)](https://ticketbaiws.eus/en/lroe-recibidas-get/)
- [`DEL`  LROE - **Received invoices**  - Cancel (BATUZ)](https://ticketbaiws.eus/en/lroe-recibidas-del/)
- [`POST`  LROE - **Expenses without invoice**  - Submit (BATUZ, form 140)](https://ticketbaiws.eus/en/lroe-gastos-sinfactura-post/)
- [`PUT`  LROE - **Expenses without invoice**  - Update (BATUZ, form 140)](https://ticketbaiws.eus/en/lroe-gastos-sinfactura-put/)
- [`GET`  LROE - **Expenses without invoice**  - Query (BATUZ, form 140)](https://ticketbaiws.eus/en/lroe-gastos-sinfactura-get/)
- [`DEL`  LROE - **Expenses without invoice**  - Cancel (BATUZ, form 140)](https://ticketbaiws.eus/en/lroe-gastos-sinfactura-del/)
- [`POST`  LROE - **Cash accounting COLLECTIONS**  - Submit (BATUZ)](https://ticketbaiws.eus/en/lroe-critcaja-cobros-post/)
- [`PUT`  LROE - **Cash accounting COLLECTIONS**  - Update (BATUZ)](https://ticketbaiws.eus/en/lroe-critcaja-cobros-put/)
- [`GET`  LROE - **Cash accounting COLLECTIONS**  - Query (BATUZ)](https://ticketbaiws.eus/en/lroe-critcaja-cobros-get/)
- [`DEL`  LROE - **Cash accounting COLLECTIONS**  - Cancel (BATUZ)](https://ticketbaiws.eus/en/lroe-critcaja-cobros-del/)
- [`POST`  LROE - **Cash accounting PAYMENTS**  - Submit (BATUZ)](https://ticketbaiws.eus/en/lroe-critcaja-pagos-post/)
- [`PUT`  LROE - **Cash accounting PAYMENTS**  - Update (BATUZ)](https://ticketbaiws.eus/en/lroe-critcaja-pagos-put/)
- [`GET`  LROE - **Cash accounting PAYMENTS**  - Query (BATUZ)](https://ticketbaiws.eus/en/lroe-critcaja-pagos-get/)
- [`DEL`  LROE - **Cash accounting PAYMENTS**  - Cancel (BATUZ)](https://ticketbaiws.eus/en/lroe-critcaja-pagos-del/)

### SII (AEAT)

- [`GET`  SII - Get the issued invoices book](https://ticketbaiws.eus/en/sii-envios-get/)
- [`POST`  SII - Received invoices (AEAT, Gipuzkoa and Araba)](https://ticketbaiws.eus/en/sii-recibidas-post/)

### Customers and products (invoicing tool)

- [`GET`  Customers - Search / get customers](https://ticketbaiws.eus/en/clientes-get/)
- [`POST`  Customers - New customer](https://ticketbaiws.eus/en/clientes-post/)
- [`PUT`  Customers - Update customer](https://ticketbaiws.eus/en/clientes-put/)
- [`GET`  Products - Search / get products](https://ticketbaiws.eus/en/productos-get/)

### Other methods

- [`POST`  Webhooks - New webhook](https://ticketbaiws.eus/en/webhooks-post/)
- [`PUT`  Webhooks - Update webhook](https://ticketbaiws.eus/en/webhooks-put/)
- [`GET`  Webhooks - List webhooks](https://ticketbaiws.eus/en/webhooks-get/)
- [`DEL`  Webhooks - Delete webhook](https://ticketbaiws.eus/en/webhooks-delete/)
- [`POST`  New company](https://ticketbaiws.eus/en/empresas-post/)
- [`PUT`  Edit company details](https://ticketbaiws.eus/en/empresas-put/)
- [`GET`  List companies](https://ticketbaiws.eus/en/empresas-get/)
- [`POST`  New license](https://ticketbaiws.eus/en/licencias-post/)
- [`GET`  List licenses](https://ticketbaiws.eus/en/licencias-get/)

Fuente: https://ticketbaiws.eus/en/api-documentation/
