# PATCH /v1/sites/{id}

Cập nhật một phần trang web

Gửi ít nhất một trường trong `category` (`mainstream`, `adult` hoặc `network`) và `notes`. Ghi chú cho đội duyệt dài tối đa 500 ký tự và được trả về trong `publisher_note`. Gửi `null` hoặc chuỗi rỗng để xoá ghi chú. Trả 200 khi cập nhật hoàn tất. Một số thay đổi thể loại trên trang web đã duyệt cần xét duyệt. Phản hồi 202 ghi thể loại được yêu cầu trong `pending_category`, còn trang web tiếp tục dùng `category` hiện tại cho đến khi duyệt xong. Gửi thể loại hiện tại để huỷ yêu cầu đang chờ. Cần quyền `publisher:write` (khoá API hoặc phiên web); không dùng được trong chế độ xem thay. Tầng giới hạn tốc độ: `write`.

- Quyền cần có: `publisher:write`
- Giới hạn tốc độ: `write` — 20 yêu cầu mỗi cửa sổ 60 giây cho mỗi API key hoặc phiên web

## Tham số

| Tên | Vị trí | Kiểu | Bắt buộc |
|---|---|---|---|
| `id` | path | integer | có |

## Nội dung yêu cầu

```
{ category?: "mainstream" | "adult" | "network"; notes?: string | null }
```

## Phản hồi

```
{ category: "mainstream" | "adult" | "network"; created_at: string; deleted_at: string | null; domain: string; id: integer; notes: string | null; pending_category: "mainstream" | "adult" | "network" | null; pending_category_at: string | null; publisher_note: string | null; status: "pending" | "approved" | "rejected"; zones_count: integer }
```

## Lỗi

Các route có giới hạn tốc độ trả `RateLimit-Limit`, `RateLimit-Remaining`, `RateLimit-Reset` (số giây tới hết cửa sổ); phản hồi 429 có thêm `Retry-After`. Header có thể vắng khi bộ giới hạn tạm thời không sẵn sàng (khi đó yêu cầu vẫn được cho qua).

| Mã | Ý nghĩa |
|---|---|
| 401 | Thiếu, sai hoặc đã thu hồi API key. |
| 403 | Key thiếu quyền cần có, hoặc thao tác không được phép với tác nhân này. |
| 429 | Vượt giới hạn tốc độ; chờ `Retry-After` giây. |
| 400 | Default Response |
| 404 | Default Response |
| 409 | Default Response |

## Ví dụ

### cURL

```bash
#!/usr/bin/env bash
# Request mainstream for a site. HTTP 202 means it keeps its current category while the request is reviewed.
# Needs AGIMONE_API_KEY, AGIMONE_SITE_ID, curl and jq. Optional AGIMONE_API_BASE overrides the API URL.
set -euo pipefail
BASE="${AGIMONE_API_BASE:-https://app.agimone.com}"
SITE_ID="${AGIMONE_SITE_ID:?Set AGIMONE_SITE_ID to the site ID}"
curl -fsS -X PATCH -H "Authorization: Bearer $AGIMONE_API_KEY" -H 'Content-Type: application/json' \
  --data '{"category":"mainstream"}' "$BASE/v1/sites/$SITE_ID" | jq -c '{category, pending_category}'
```

### Node.js

```js
// Request mainstream for a site. HTTP 202 means it keeps its current category while the request is reviewed.
// Needs AGIMONE_API_KEY, AGIMONE_SITE_ID and Node 18+. Optional AGIMONE_API_BASE overrides the API URL.
const base = process.env.AGIMONE_API_BASE ?? 'https://app.agimone.com';
const siteId = process.env.AGIMONE_SITE_ID;
if (!siteId) {
  console.error('Set AGIMONE_SITE_ID to the site ID.');
  process.exit(1);
}

const res = await fetch(`${base}/v1/sites/${siteId}`, {
  method: 'PATCH',
  headers: { Authorization: `Bearer ${process.env.AGIMONE_API_KEY}`, 'Content-Type': 'application/json' },
  body: JSON.stringify({ category: 'mainstream' }),
});
if (!res.ok) {
  console.error(`HTTP ${res.status}: ${await res.text()}`);
  process.exit(1);
}
const { category, pending_category } = await res.json();
console.log(JSON.stringify({ category, pending_category }));
```

### PHP

```php
<?php
// Request mainstream for a site. HTTP 202 means it keeps its current category while the request is reviewed.
// Needs AGIMONE_API_KEY, AGIMONE_SITE_ID and PHP 8 with cURL. Optional AGIMONE_API_BASE overrides the API URL.
$base = getenv('AGIMONE_API_BASE') ?: 'https://app.agimone.com';
$siteId = getenv('AGIMONE_SITE_ID');
if (!$siteId) {
    fwrite(STDERR, "Set AGIMONE_SITE_ID to the site ID.\n");
    exit(1);
}

$ch = curl_init("$base/v1/sites/$siteId");
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'PATCH',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('AGIMONE_API_KEY'), 'Content-Type: application/json'],
    CURLOPT_POSTFIELDS => json_encode(['category' => 'mainstream']),
    CURLOPT_TIMEOUT => 15,
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
if ($body === false || $status >= 400) {
    fwrite(STDERR, "HTTP $status: " . ($body === false ? curl_error($ch) : $body) . "\n");
    exit(1);
}
curl_close($ch);
$site = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
echo json_encode(['category' => $site['category'], 'pending_category' => $site['pending_category']]), "\n";
```

### Python

```python
# Request mainstream for a site. HTTP 202 means it keeps its current category while the request is reviewed.
# Needs AGIMONE_API_KEY, AGIMONE_SITE_ID and Python 3.8+. Optional AGIMONE_API_BASE overrides the API URL.
import json
import os
import sys
import urllib.error
import urllib.request

base = os.environ.get("AGIMONE_API_BASE", "https://app.agimone.com")
site_id = os.environ.get("AGIMONE_SITE_ID")
if not site_id:
    sys.exit("Set AGIMONE_SITE_ID to the site ID.")

req = urllib.request.Request(
    f"{base}/v1/sites/{site_id}",
    data=json.dumps({"category": "mainstream"}).encode("utf-8"),
    headers={
        "Authorization": f"Bearer {os.environ['AGIMONE_API_KEY']}",
        "Content-Type": "application/json",
    },
    method="PATCH",
)
try:
    with urllib.request.urlopen(req, timeout=15) as res:
        site = json.load(res)
        print(json.dumps({"category": site["category"], "pending_category": site["pending_category"]}))
except urllib.error.HTTPError as e:
    print(f"HTTP {e.code}: {e.read().decode()}", file=sys.stderr)
    sys.exit(1)
```

Tài liệu HTML: https://agimone.com/vi/developers/api/#patch-site
API 2026-10
