> For the complete documentation index, see [llms.txt](https://trust-positif.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trust-positif.gitbook.io/docs/guides/examples.md).

# Code examples

```bash
export BASE_URL="https://trustpositif.id/api/v1"
export API_KEY="tp_your_key_here"
```

## cURL

### Check domains

```bash
curl -sS -X POST "${BASE_URL}/check" \
  -H "Content-Type: application/json" \
  -H "X-API-Key: ${API_KEY}" \
  -d '{"domains": "example.com\ngoogle.co.id"}' | jq .
```

### Get quota

```bash
curl -sS "${BASE_URL}/limit" \
  -H "X-API-Key: ${API_KEY}" | jq .
```

## PHP (Guzzle)

```php
<?php

use GuzzleHttp\Client;

$client = new Client([
    'base_uri' => 'https://trustpositif.id/api/v1/',
    'timeout' => 60,
]);

$response = $client->post('check', [
    'headers' => [
        'X-API-Key' => getenv('TRUSTPOSITIVE_API_KEY'),
        'Accept' => 'application/json',
    ],
    'json' => [
        'domains' => "example.com\ngoogle.co.id",
    ],
]);

$data = json_decode($response->getBody()->getContents(), true);

foreach ($data['results'] ?? [] as $row) {
    $status = $row['Blocked'] ? 'TERBLOKIR' : 'AMAN';
    echo "{$row['Domain']}: {$status}\n";
}
```

## JavaScript (Node 18+ fetch)

```javascript
const BASE_URL = 'https://trustpositif.id/api/v1';
const API_KEY = process.env.TRUSTPOSITIVE_API_KEY;

async function checkDomains(domains) {
  const res = await fetch(`${BASE_URL}/check`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'X-API-Key': API_KEY,
    },
    body: JSON.stringify({
      domains: domains.join('\n'),
    }),
  });

  const data = await res.json();
  if (!data.success) {
    throw new Error(data.message || `HTTP ${res.status}`);
  }
  return data;
}

checkDomains(['example.com', 'google.co.id'])
  .then((data) => console.log(data.results))
  .catch(console.error);
```

## Python (requests)

```python
import os
import requests

BASE_URL = "https://trustpositif.id/api/v1"
API_KEY = os.environ["TRUSTPOSITIVE_API_KEY"]

def check_domains(domains: list[str]) -> dict:
    response = requests.post(
        f"{BASE_URL}/check",
        headers={"X-API-Key": API_KEY},
        json={"domains": "\n".join(domains)},
        timeout=60,
    )
    response.raise_for_status()
    data = response.json()
    if not data.get("success"):
        raise RuntimeError(data.get("message", "API error"))
    return data

if __name__ == "__main__":
    result = check_domains(["example.com", "google.co.id"])
    for row in result["results"]:
        label = "BLOCKED" if row["Blocked"] else "AMAN"
        print(f"{row['Domain']}: {label}")
```

## Batch processing (premium)

```javascript
const CHUNK = 100;
const COST_MULTIPLIER = 3;

async function checkAll(domains, apiKey) {
  const limitRes = await fetch(`${BASE_URL}/limit`, {
    headers: { 'X-API-Key': apiKey },
  });
  const { limit } = await limitRes.json();
  const needed = domains.length * COST_MULTIPLIER;
  if (limit.quota?.remaining < needed) {
    throw new Error(`Need ${needed} credits, have ${limit.quota.remaining}`);
  }

  const results = [];
  for (let i = 0; i < domains.length; i += CHUNK) {
    const chunk = domains.slice(i, i + CHUNK);
    const res = await fetch(`${BASE_URL}/check`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'X-API-Key': apiKey,
      },
      body: JSON.stringify({ domains: chunk.join('\n') }),
    });
    const data = await res.json();
    if (!data.success) throw new Error(data.message);
    results.push(...data.results);
  }
  return results;
}
```

## Pemantauan berkala

API **tidak** menyediakan webhook. Untuk cek otomatis:

* Gunakan [Dashboard](https://trustpositif.id/dashboard) → Domain otomatis, atau
* Jadwalkan cron job yang memanggil `POST /check`.
