# 웹훅 업데이트 (PUT)

웹훅의 이름, 메시지 템플릿, 기본 중요도, 액션 버튼, 활성 상태를 업데이트해요. 생략한 필드는 현재 값을 그대로 유지해요.

## 엔드포인트

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

## 인증

> **Info: 필수**
>
> 요청에 다음 헤더 중 하나를 포함하세요:
> - `Token: <your-api-key>` — [API 키](https://pocketalert.app/account/apikeys)에서 발급받을 수 있어요
> - `Authorization: Bearer <jwt-token>` — [로그인](https://info.pocketalert.app/api/user/login.md)에서 받을 수 있어요

## 요청

### 경로 파라미터

| 파라미터 | 타입 | 필수 | 설명 |
|-----------|------|:--------:|-------------|
| `tid` | string | ✅ | 웹훅 고유 식별자 |

### 헤더

| 헤더 | 필수 | 설명 |
|--------|:--------:|-------------|
| `Token` | ✅ | API 키 |
| `Authorization` | ✅ | `Bearer <jwt-token>` |

### 본문 파라미터

| 파라미터 | 타입 | 필수 | 설명 |
|-----------|------|:--------:|-------------|
| `name` | string | ❌ | 새 이름 |
| `url` | string | ❌ | 수신 URL `https://p4a.me/wh/{url}`의 새 슬러그예요. 기존 URL은 더 이상 작동하지 않아요. 이미 사용 중인 슬러그라면 `409`를 반환해요 |
| `message` | string | ❌ | 새 메시지 템플릿 |
| `is_active` | boolean | ❌ | 웹훅 활성화/비활성화 |
| `application_id` | string | ❌ | 새 애플리케이션 TID |
| `device_id` | string | ❌ | 새 기기 TID |
| `default_level` | string \| int \| null | ❌ | 페이로드에 `level`이 없을 때 이 웹훅이 보내는 메시지의 기본 우선순위예요. 이름(`silent`…`critical`) 또는 정수(`-2`..`2`)를 사용할 수 있어요. `null`로 설정하면 제거되어 애플리케이션의 중요도가 적용돼요 |
| `actions` | string | ❌ | `%field.path%` 플레이스홀더를 포함한 JSON 액션 버튼 템플릿이에요. 자세한 내용은 [웹훅 생성](https://info.pocketalert.app/api/webhooks/create.md#action-buttons-template)을 참고하세요. `""`를 입력하면 버튼이 제거돼요 |

> **Warning: 웹훅 비활성화**
>
> `is_active: false`인 웹훅도 수신 요청을 받고 `200`으로 응답해요. 하지만 알림은 생성되지 않아요. 이런 호출은 [웹훅 기록](https://info.pocketalert.app/api/webhooks/history.md)에 `error_code: inactive`로 남아요.

### 요청 예시

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

## 응답

### 성공 응답

> **Tip: 200 OK**
>
> 웹훅이 성공적으로 업데이트되었어요

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

### 오류 응답

| 상태 | 설명 |
|:------:|-------------|
| `400` | 잘못된 요청 — 잘못된 `default_level` 또는 `actions` 템플릿이거나, `name` 또는 `message`가 비어 있어요 |
| `401` | 인증 실패 — 토큰이 잘못되었거나 없어요 |
| `404` | 찾을 수 없음 — 웹훅, 애플리케이션 또는 기기가 존재하지 않아요 |
| `409` | 충돌 — `url` 슬러그가 이미 사용 중이에요 |
