# Aggiornare un webhook (PUT)

Aggiorna il nome, il template del messaggio, il livello predefinito, i pulsanti di azione o lo stato di attività di un webhook. I campi omessi mantengono il valore attuale.

## Endpoint

```
PUT https://api.pocketalert.app/v1/webhooks/{tid}
```

## Autenticazione

> **Info: Obbligatorio**
>
> Includi uno di questi header nella richiesta:
> - `Token: <your-api-key>` — Ottienila da [Chiavi API](https://pocketalert.app/account/apikeys)
> - `Authorization: Bearer <jwt-token>` — Da [Accedi](https://info.pocketalert.app/api/user/login.md)

## Richiesta

### Parametri del percorso

| Parametro | Tipo | Obbligatorio | Descrizione |
|-----------|------|:--------:|-------------|
| `tid` | string | ✅ | Identificatore univoco del webhook |

### Header

| Header | Obbligatorio | Descrizione |
|--------|:--------:|-------------|
| `Token` | ✅ | La tua chiave API |
| `Authorization` | ✅ | `Bearer <jwt-token>` |

### Parametri del body

| Parametro | Tipo | Obbligatorio | Descrizione |
|-----------|------|:--------:|-------------|
| `name` | string | ❌ | Nuovo nome |
| `url` | string | ❌ | Nuovo slug dell'URL di ricezione `https://p4a.me/wh/{url}`. Il vecchio URL smette di funzionare. Uno slug già in uso restituisce `409` |
| `message` | string | ❌ | Nuovo template del messaggio |
| `is_active` | boolean | ❌ | Abilita/Disabilita il webhook |
| `application_id` | string | ❌ | Nuovo TID dell'applicazione |
| `device_id` | string | ❌ | Nuovo TID del dispositivo |
| `default_level` | string \| int \| null | ❌ | Livello di priorità predefinito per i messaggi di questo webhook quando il payload non contiene `level`: un nome (`silent`…`critical`) oppure un intero (`-2`..`2`). `null` lo rimuove, quindi si applica il livello dell'applicazione |
| `actions` | string | ❌ | Template JSON dei pulsanti di azione con i segnaposto `%field.path%`, vedi [Crea webhook](https://info.pocketalert.app/api/webhooks/create.md#action-buttons-template). `""` rimuove i pulsanti |

> **Warning: Disabilitare un webhook**
>
> Un webhook con `is_active: false` continua ad accettare le richieste in arrivo e risponde con `200`, ma non viene creato alcun avviso. Queste chiamate vengono registrate nella [Cronologia webhook](https://info.pocketalert.app/api/webhooks/history.md) con `error_code: inactive`.

### Esempio di richiesta

**cURL**

```bash
curl -X PUT "https://api.pocketalert.app/v1/webhooks/kblf7mh9j8jjyeh4fx" \
  -H "Token: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "GitHub Push (Inactive)",
    "is_active": false
  }'
```

**JavaScript**

```javascript
const tid = 'kblf7mh9j8jjyeh4fx';
const response = await fetch(`https://api.pocketalert.app/v1/webhooks/${tid}`, {
  method: 'PUT',
  headers: {
    'Token': 'your-api-key',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    name: 'GitHub Push (Inactive)',
    is_active: false
  })
});
```

**Python**

```python
import requests

tid = 'kblf7mh9j8jjyeh4fx'
response = requests.put(
    f'https://api.pocketalert.app/v1/webhooks/{tid}',
    headers={'Token': 'your-api-key'},
    json={'name': 'GitHub Push (Inactive)', 'is_active': False}
)
print(response.json())
```

**PHP**

```php
$tid = 'kblf7mh9j8jjyeh4fx';
$response = Http::withHeaders([
    'Token' => 'your-api-key',
])->put('https://api.pocketalert.app/v1/webhooks/'.$tid, [
    'name' => 'GitHub Push (Inactive)',
    'is_active' => false,
]);

return $response->json();
```

## Risposta

### Risposta di successo

> **Tip: 200 OK**
>
> Webhook aggiornato con successo

```json
{
  "data": "success"
}
```

### Risposte di errore

| Stato | Descrizione |
|:------:|-------------|
| `400` | Bad Request — un `default_level` o un template `actions` non valido, oppure un `name` o un `message` vuoto |
| `401` | Unauthorized — token non valido o mancante |
| `404` | Not Found — webhook, applicazione o dispositivo non esistente |
| `409` | Conflict — lo slug `url` è già in uso |
