## 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. Ejemplo: `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. Ejemplo: `xajky22kjasy`
- `solo_errores` (boolean, optional): Send the webhook only when there are errors or when the invoice is accepted with errors or warnings. Ejemplo: `true`
- `activo` (boolean, optional): Webhook enabled. Lets you switch the webhook off temporarily. Ejemplo: `true`
- `eventos` (array, optional): Events notified to this webhook. Default **["cambio_estado"]** . See the events table. Ejemplo: `["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](https://ticketbaiws.eus/es/factura-electronica-b2b/) (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](https://ticketbaiws.eus/en/spfe-estados-post/). Same fields as [GET spfe-estados](https://ticketbaiws.eus/en/spfe-estados-get/).)
- `spfe_recibida` (, B2B e-invoicing: new invoice received from a supplier through the SPFE. Same fields as [GET spfe-recibidas](https://ticketbaiws.eus/en/spfe-recibidas-get/). 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.

**POST** `https://{entorno}.ticketbaiws.eus/webhooks/`

```bash
$ 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"]
}'
```

Respuesta:

```json
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": ""
}
```

Example notification:

```json
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":""}
```

Example notification spfe_envio (B2B e-invoice):

```json
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":""}
```

Example notification spfe_recibida (B2B e-invoice):

```json
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"}
```

Fuente: https://ticketbaiws.eus/en/webhooks-post/
