> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.divert.ly/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.divert.ly/_mcp/server.

# API Guide

> Divertly API conventions and endpoint notes: response envelope, pagination, domain toggle and verification, risk, QR codes, and email.

This guide covers how the API behaves in general, plus the endpoints that aren't self-explanatory. For a complete list of endpoints, see the [API Reference](/docs/developers/api-reference). The examples assume you've set `CREDENTIAL` as described in [Authentication](/docs/developers/authentication).

## Responses

A successful response wraps its payload in a `body` field:

```json
{ "body": { "id": "5f0c…", "slug": "spring", "enabled": true } }
```

List endpoints return an array in `body`. Failed requests return an `error` message and a stable `errorCode`. See [Rate Limits & Errors](/docs/developers/rate-limits-errors). The HTTP status line is the only place the status is reported.

## Pagination

List endpoints that return a `meta` block accept two query parameters:

| Parameter | Description                                      |
| --------- | ------------------------------------------------ |
| `page`    | The page to return, starting at 1.               |
| `size`    | Results per page, from 1 to 256. Defaults to 20. |

```bash
curl "https://api.divert.ly/v1/organizations/{org_id}/audit-events?page=2&size=50" \
  -H "Authorization: Key $CREDENTIAL"
```

`meta` reports `currentPage`, `pageSize`, `totalCount`, and `totalPages`, so you know when to stop.

## Enable or disable a domain

`PUT /v1/domains/{domain_id}/toggle` **flips** the domain's `enabled` flag and returns the old and new values. A disabled domain stops serving redirects but keeps its configuration.

```bash
curl -X PUT https://api.divert.ly/v1/domains/{domain_id}/toggle \
  -H "Authorization: Key $CREDENTIAL"
```

```json
{ "body": { "oldValue": true, "newValue": false } }
```

Because it flips rather than sets, **calling it twice reverses it**. If a call times out and you aren't sure whether it applied, read the domain and check `enabled` before calling again.

## Verify a domain

Verification is two calls. `GET /v1/domains/{domain_id}/verify-info` returns the DNS records to publish (`cnameKey`, `cnameValue`, `txtKey`, `txtValue`). Once they're in place, `GET /v1/domains/{domain_id}/verify` looks for the record and marks the domain verified. The response's `verified` field tells you the result. See [Bring Your Own Domain](/docs/user-guides/bring-your-own-domain).

## Risk verdicts

Domains and targets have a risk verdict, described in [Security & Risk](/docs/concepts/security-risk).

```bash
# Read the stored verdict
curl https://api.divert.ly/v1/domains/{domain_id}/risk \
  -H "Authorization: Key $CREDENTIAL"

# Force a fresh check
curl -X POST https://api.divert.ly/v1/domains/{domain_id}/risk \
  -H "Authorization: Key $CREDENTIAL"
```

The same pair of endpoints exists for a target at `/v1/domains/{domain_id}/routes/{route_id}/targets/{target_id}/risk`. The verdict has a `status` (`unknown`, `pending`, `clean`, or `flagged`), a `score`, the `thresholdAtCheck` it was compared with, an optional `reason`, and `lastCheckedAt`. A `POST` bypasses the cache and is **rate limited separately** from your normal API limit, so use it when you need a fresh answer, not on a schedule. If the risk service can't be reached, the check is recorded as `pending`. See [Errata](/docs/developers/errata).

## QR codes

A route can have one QR code at a time.

| Call                                                   | Purpose                                   |
| ------------------------------------------------------ | ----------------------------------------- |
| `POST /v1/domains/{domain_id}/routes/{route_id}/qr`    | Generate the QR code.                     |
| `GET /v1/domains/{domain_id}/routes/{route_id}/qr`     | Read the QR code's metadata.              |
| `GET /v1/domains/{domain_id}/routes/{route_id}/qr.png` | Download the image.                       |
| `DELETE /v1/domains/{domain_id}/routes/{route_id}/qr`  | Delete it, so you can generate a new one. |

```bash
curl https://api.divert.ly/v1/domains/{domain_id}/routes/{route_id}/qr.png \
  -H "Authorization: Key $CREDENTIAL" -o route-qr.png
```

## Outbound email

`GET /v1/organizations/{org_id}/emails` lists the email the platform has sent on your organization's behalf, most recent first. That includes welcome emails and notices about domain verification and risk changes. Each entry has the recipient, subject, type, and delivery `status`. Use it to confirm that a notification went out. It's paginated.

## Entitlements

`GET /v1/organizations/{org_id}/entitlements` returns what your plan allows: `clickLimit`, `domainLimit`, `rateLimitCpm`, and `targetStrategies`. Limits are enforced. See [Subscriptions](/docs/organization/subscriptions).

## Who am I

`GET /v1/whoami` resolves a credential to its organization. Use it to check that a key works.

## Not yet available

Traffic metrics aren't available through the API yet. They're coming soon.