# PATCH /v1/sites/{id}

Atualizar um site parcialmente

Envie pelo menos um dos campos `category` (`mainstream`, `adult` ou `network`) e `notes`. A nota para a equipe de análise pode ter até 500 caracteres e é retornada em `publisher_note`. Para apagá-la, envie `null` ou uma string vazia. Retorna 200 quando a atualização é concluída. Algumas mudanças de categoria de sites já aprovados precisam de análise. A resposta 202 informa a categoria solicitada em `pending_category`, e o site mantém sua `category` atual até o fim da análise. Envie a categoria atual para cancelar a solicitação pendente. Exige o escopo `publisher:write` (chave de API ou sessão web); não disponível em view-as. Nível de limite de taxa: `write`.

- Escopo exigido: `publisher:write`
- Limite de taxa: `write` — 20 requisições por janela de 60 s por chave de API ou sessão web

## Parâmetros

| Nome | Em | Tipo | Obrigatório |
|---|---|---|---|
| `id` | path | integer | sim |

## Corpo da chamada

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

## Resposta

```
{ 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 }
```

## Erros

As rotas com limite de taxa retornam `RateLimit-Limit`, `RateLimit-Remaining` e `RateLimit-Reset` (segundos até o fim da janela); um 429 também traz `Retry-After`. Os headers podem estar ausentes enquanto o limitador estiver temporariamente indisponível (as requisições passam nesse caso).

| Status | Significado |
|---|---|
| 401 | Chave de API ausente, inválida ou revogada. |
| 403 | A chave não tem o escopo exigido, ou a operação não é permitida para este ator. |
| 429 | Limite de taxa excedido; aguarde `Retry-After` segundos. |
| 400 | Default Response |
| 404 | Default Response |
| 409 | Default Response |

## Exemplos

### 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)
```

Documentação HTML: https://agimone.com/pt/developers/api/#patch-site
API 2026-10
