Webhooks - New webhook
POST https://{entorno}.ticketbaiws.eus/webhooks/
Creates a webhook that notifies you when an invoice changes status after an asynchronous submission and, with the eventos parameter, of B2B e-invoicing (SPFE) events.
Available in the test and production environments. Each environment has its own webhooks: create it with api-test and the test token to receive notifications for test invoices, and with api and the production token for real ones. Each notification carries the X-TbaiWs-Environment header with the environment (test or real).
PARAMETERS
| url string required URL the webhook is sent to | https://... |
| secret string required Secret key used to sign the webhook so its content can be validated. The signature is computed with HMAC SHA256 and sent base64-encoded in the X-Tbaiws-Hmac-Sha256 header | xajky22kjasy |
| solo_errores boolean optional Send the webhook only when there are errors or when the invoice is accepted with errors or warnings | true |
| activo boolean optional Webhook enabled. Lets you switch the webhook off temporarily | true |
| eventos array optional Events notified to this webhook. Default ["cambio_estado"]. See the events table | ["cambio_estado", "spfe_envio"] |
How to compute the signature in PHP:
$calculated_hmac = base64_encode(hash_hmac('sha256', $request_body , $secret, true));
EVENTS
| cambio_estado Default. Result of submitting an asynchronously sent invoice to the tax authority (TicketBAI or Verifactu): serie, numero, fecha_emision, estado (OK / ERROR) and avisos. |
| spfe_envio B2B e-invoicing: the AEAT (Spanish Tax Agency) has accepted or rejected an invoice sent to the SPFE (Spanish public B2B e-invoicing platform), either a registration or a cancellation, or the invoice could not be sent because data is missing. Includes serie, numero, fecha_emision, nif_cliente, tipo (alta / anulacion), estado (OK / ERROR), errores and localizador. |
| spfe_estado B2B e-invoicing: result of a payment, collection, rejection or non-payment reported with POST spfe-estados. Same fields as GET spfe-estados. |
| spfe_recibida B2B e-invoicing: new invoice received from a supplier through the SPFE. Same fields as GET spfe-recibidas. Sent even if the webhook has solo_errores set. |
Each notification carries the X-TbaiWs-Topic header with the event name. All events include codigo_webhook, nif and evento in the JSON (for cambio_estado, since 28/11/2026). With solo_errores, spfe_envio and spfe_estado are only notified when the result is ERROR.
$ curl --request POST \
--url https://api-test.ticketbaiws.eus/webhooks/ \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'Token: xxx' \
--header 'Nif: 00000014Z'
--data '
{
"url": "https://www.berein.com/",
"secret": "xajky22kjasy",
"solo_errores" : true,
"activo": true,
"eventos": ["cambio_estado", "spfe_envio", "spfe_recibida"]
}'
$ 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->crearWebhook('https://www.berein.com/', 'xajky22kjasy', true, true);
if ($r->isError()) {
echo $r->getMessageText();
} else {
echo $r->getData('codigo');
}
$ python -m pip install requests
import requests
url = "https://api-test.ticketbaiws.eus/webhooks/"
payload = {
"url": "https://www.berein.com/",
"secret": "xajky22kjasy",
"solo_errores" : true,
"activo": true,
"eventos": ["cambio_estado", "spfe_envio", "spfe_recibida"]
}
headers = {"Accept": "application/json", "Token" : "xxx", "Nif" : "00000014Z"}
response = requests.request("POST", url, json=payload, headers=headers)
print(response.text)
CURL *hnd = curl_easy_init();
curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(hnd, CURLOPT_URL, "https://api-test.ticketbaiws.eus/webhooks/");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Accept: application/json");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, '{"url": "https://www.berein.com/","secret": "xajky22kjasy","solo_errores" : true,"activo": true,"eventos": ["cambio_estado","spfe_envio","spfe_recibida"]}');
CURLcode ret = curl_easy_perform(hnd);
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, '{"url": "https://www.berein.com/","secret": "xajky22kjasy","solo_errores" : true,"activo": true,"eventos": ["cambio_estado","spfe_envio","spfe_recibida"]}');
Request request = new Request.Builder()
.url("https://api-test.ticketbaiws.eus/webhooks/")
.post(body)
.addHeader("Accept", "application/json")
.addHeader("Token", "xxx")
.addHeader("Nif", "00000014Z")
.build();
Response response = client.newCall(request).execute();
HTTP/1.1 200 OK
{
"result": "OK",
"return": {
"codigo": "6904a3501874e",
"url": "https://www.berein.com/",
"entorno": "test",
"secret": "xajky22kjasy",
"solo_errores": true,
"activo": true,
"fecha_creado": "2025-10-31T12:53:52+01:00",
"fecha_modificado": "2025-11-03T10:16:15+01:00",
"eventos": ["cambio_estado", "spfe_envio", "spfe_recibida"]
},
"msg": ""
}
Headers:
array (
'X-Tbaiws-Hmac-Sha256' => 'Hl+X3FT/r5yH3wsgaku46votvTpUPSLPeDNCiCj+syM=',
'X-Tbaiws-Topic' => 'cambio_estado',
'X-Tbaiws-Environment' => 'real',
'X-Tbaiws-Id' => '6904a3501884e',
'User-Agent' => 'TbaiWS Hook',
'Content-Type' => 'application/json',
'Content-Length' => '168',
'Connection' => 'close'
)
Payload:
{"codigo_webhook":"6904a3501884e","nif":"B123456789","evento":"cambio_estado","serie":"5","numero":"500593135","fecha_emision":"03\/11\/2025","estado":"OK","avisos":""}
Headers:
'X-Tbaiws-Topic' => 'spfe_envio'
Payload:
{"codigo_webhook":"6904a3501884e","nif":"B123456789","evento":"spfe_envio","serie":"A","numero":"2026000245","fecha_emision":"28\/10\/2026","nif_cliente":"B01000012","tipo":"alta","estado":"ERROR","errores":[{"codigo":"SPFE-CORE-39","descripcion":"Es obligatorio informar la ciudad del comprador"}],"localizador":""}
Headers:
'X-Tbaiws-Topic' => 'spfe_recibida'
Payload:
{"codigo_webhook":"6904a3501884e","nif":"B123456789","evento":"spfe_recibida","id":57,"factura":"F2026-0153","fecha_factura":"03\/11\/2026","tipo_factura":"380","copia":false,"nif_emisor":"B01000012","nombre_emisor":"Empresa de ejemplo S.L.","base":250,"cuota":52.5,"total":302.5,"vencimiento":"03\/12\/2026","estado":"pendiente","localizador":"LOCGENV1:O:NdjdSHy1PAqwlw...","fecha_descarga":"04\/11\/2026 10:05:12"}
TicketBAI / Verifactu methods
- POST New invoice / resubmission (zuzendu) TicketBAI / Verifactu
- POST Complete a simplified invoice
- GET Get a TicketBAI / Verifactu invoice
- GET List TicketBAI / Verifactu invoices
- GET Download TicketBAI / Verifactu XML
- GET Download invoice in FacturaE format
- GET Download invoice as PDF
- GET System status
- DEL Cancel a TicketBAI / Verifactu invoice
- PUT Force TicketBAI / Verifactu resend
- POST Validate a NIF with the AEAT
- POST Validate a VAT number in VIES
Representation document
- GET Representation document - Download template
- POST Representation document - Upload document
- GET Representation document - Download uploaded document
- DELETE Representation document - Revoke uploaded document
BATUZ BIZKAIA specific methods
- GET List IAE activity codes
- POST LROE - Received invoices - Submit (BATUZ)
- PUT LROE - Received invoices - Update (BATUZ)
- GET LROE - Received invoices - Query (BATUZ)
- DEL LROE - Received invoices - Cancel (BATUZ)
- POST LROE - Expenses without invoice - Submit (BATUZ, form 140)
- PUT LROE - Expenses without invoice - Update (BATUZ, form 140)
- GET LROE - Expenses without invoice - Query (BATUZ, form 140)
- DEL LROE - Expenses without invoice - Cancel (BATUZ, form 140)
- POST LROE - Cash accounting COLLECTIONS - Submit (BATUZ)
- PUT LROE - Cash accounting COLLECTIONS - Update (BATUZ)
- GET LROE - Cash accounting COLLECTIONS - Query (BATUZ)
- DEL LROE - Cash accounting COLLECTIONS - Cancel (BATUZ)
- POST LROE - Cash accounting PAYMENTS - Submit (BATUZ)
- PUT LROE - Cash accounting PAYMENTS - Update (BATUZ)
- GET LROE - Cash accounting PAYMENTS - Query (BATUZ)
- DEL LROE - Cash accounting PAYMENTS - Cancel (BATUZ)
SII (AEAT)
Customers and products (invoicing tool)
- GET Customers - Search / get customers
- POST Customers - New customer
- PUT Customers - Update customer
- GET Products - Search / get products
