API

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: from zero to your first invoice in production.
  • Examples: 22 ready-to-copy cases (simplified, intra-EU, corrective invoices…).
  • Test console: try the API without creating an account.
  • Service status: 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 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 and licenses 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/ or set up a webhook. If you need the tax authority's response in the same request, send "sincrono": true in POST /tbai/. 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

REST API

TicketBAI Batuz Bizkaia

TicketBAI Gipuzkoa

TicketBAI Araba

Spanish Tax Agency AEAT Verifactu

GET https://{entorno}.ticketbaiws.eus/status/
$ 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'
$ composer require ticketbaiws/ticketbaiws-php
<?php
// Installation: composer require ticketbaiws/ticketbaiws-php
require 'vendor/autoload.php';

$tbai = new \TicketbaiWS\Client('xxx', '00000014Z', ['entorno' => 'test']);

$r = $tbai->estado();

if ($r->isError()) {
    echo $r->getMessageText();
} else {
    echo $r->getResult() . ' ' . $r->getMessageText();
}
$ python -m pip install requests
import requests

url = "https://api-test.ticketbaiws.eus/status/"
headers = {"Accept": "application/json", "Token" : "xxx", "Nif" : "00000014Z"}
response = requests.request("GET", url, headers=headers)
print(response.text)
CURL *hnd = curl_easy_init();

curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(hnd, CURLOPT_URL, "https://api-test.ticketbaiws.eus/status/");

struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Accept: application/json");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);

CURLcode ret = curl_easy_perform(hnd);
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://api-test.ticketbaiws.eus/status/")
  .get()
  .addHeader("Accept", "application/json")
  .addHeader("Token", "xxx")
  .addHeader("Nif", "00000014Z")
  .build();
  
Response response = client.newCall(request).execute();
{ } Response 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

Representation document

BATUZ BIZKAIA specific methods

SII (AEAT)

Customers and products (invoicing tool)

Other methods