# Update Device (PUT)

Perbarui nama atau pengaturan perangkat.

## Endpoint

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

## Autentikasi

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

## Permintaan

### Path Parameters

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

### Headers

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

### Body Parameters

| Parameter | Type | Required | Description |
|-----------|------|:--------:|-------------|
| `name` | string | ✅ | Nama perangkat yang baru |

### Contoh Permintaan

**cURL**

```bash
curl -X PUT "https://api.pocketalert.app/v1/devices/9dc24hqldvv2bfx2nlc6r" \
  -H "Token: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{"name": "My iPhone"}'
```

**JavaScript**

```javascript
const tid = '9dc24hqldvv2bfx2nlc6r';
const response = await fetch(`https://api.pocketalert.app/v1/devices/${tid}`, {
  method: 'PUT',
  headers: {
    'Token': 'your-api-key',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ name: 'My iPhone' })
});
```

**Python**

```python
import requests

tid = '9dc24hqldvv2bfx2nlc6r'
response = requests.put(
    f'https://api.pocketalert.app/v1/devices/{tid}',
    headers={'Token': 'your-api-key'},
    json={'name': 'My iPhone'}
)
print(response.json())
```

**PHP**

```php
$tid = '9dc24hqldvv2bfx2nlc6r';
$response = Http::withHeaders([
    'Token' => 'your-api-key',
])->put('https://api.pocketalert.app/v1/devices/'.$tid, [
    'name' => 'My iPhone',
]);

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

## Respons

### Respons Sukses

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

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

### Respons Error

| Status | Description |
|:------:|-------------|
| `401` | Unauthorized — Token tidak valid atau tidak ada |
| `404` | Not Found — Perangkat tidak ditemukan |
| `400` | Bad Request — isi permintaan tidak valid |
