# Update Webhook (PUT)

Perbarui nama, templat pesan, level default, tombol aksi, atau status aktif webhook. Field yang tidak disertakan akan tetap menggunakan nilai saat ini.

## Endpoint

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

## Autentikasi

> **Info: Required**
>
> Sertakan salah satu header berikut dalam permintaan Anda:
> - `Token: <your-api-key>` — Dapatkan dari [Kunci API](https://pocketalert.app/account/apikeys)
> - `Authorization: Bearer <jwt-token>` — Dari [Masuk](https://info.pocketalert.app/api/user/login.md)

## Permintaan

### Path Parameters

| Parameter | Type | Required | Description |
|-----------|------|:--------:|-------------|
| `tid` | string | ✅ | Pengenal unik webhook |

### Headers

| Header | Required | Description |
|--------|:--------:|-------------|
| `Token` | ✅ | Kunci API Anda |
| `Authorization` | ✅ | `Bearer <jwt-token>` |

### Body Parameters

| Parameter | Type | Required | Description |
|-----------|------|:--------:|-------------|
| `name` | string | ❌ | Nama baru |
| `url` | string | ❌ | Slug baru untuk URL penerima `https://p4a.me/wh/{url}`. URL lama tidak lagi berfungsi. Slug yang sudah dipakai akan mengembalikan `409` |
| `message` | string | ❌ | Templat pesan baru |
| `is_active` | boolean | ❌ | Aktifkan/nonaktifkan webhook |
| `application_id` | string | ❌ | TID aplikasi baru |
| `device_id` | string | ❌ | TID perangkat baru |
| `default_level` | string \| int \| null | ❌ | Level prioritas default untuk pesan dari webhook ini ketika payload tidak memiliki `level`: nama (`silent`…`critical`) atau int (`-2`..`2`). `null` akan menghapusnya, sehingga level aplikasi yang berlaku |
| `actions` | string | ❌ | Templat JSON tombol aksi dengan placeholder `%field.path%`, lihat [Create Webhook](https://info.pocketalert.app/api/webhooks/create.md#action-buttons-template). `""` menghapus tombol |

> **Warning: Disabling a webhook**
>
> Webhook dengan `is_active: false` tetap menerima permintaan masuk dan merespons `200`, tetapi tidak ada alert yang dibuat. Panggilan tersebut dicatat di [Riwayat Webhook](https://info.pocketalert.app/api/webhooks/history.md) dengan `error_code: inactive`.

### Contoh Permintaan

**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();
```

## Respons

### Respons Sukses

> **Tip: 200 OK**
>
> Webhook berhasil diperbarui

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

### Respons Error

| Status | Description |
|:------:|-------------|
| `400` | Bad Request — `default_level` atau templat `actions` tidak valid, atau `name` atau `message` kosong |
| `401` | Unauthorized — Token tidak valid atau tidak ada |
| `404` | Not Found — Webhook, aplikasi, atau perangkat tidak ada |
| `409` | Conflict — slug `url` sudah digunakan |
