## Webhooks - Update webhook

`PUT`  https://{entorno}.ticketbaiws.eus/webhooks/{codigo_webhook}/

Updates an existing webhook (URL, secret, errors only, enabled or events).

**Available in the test and production environments.**  Use the same environment the webhook was created in (**api-test**  or **api** ).

**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 (see [events](https://ticketbaiws.eus/en/webhooks-post/)). If not sent, the current ones are kept. Ejemplo: `["cambio_estado", "spfe_envio"]`

How to compute the signature in PHP:
$calculated_hmac = base64_encode(hash_hmac('sha256', $request_body , $secret, true));

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

```bash
$ curl --request PUT \
     --url https://api-test.ticketbaiws.eus/webhooks/6904a3501884e/ \
     --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":""}
```

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