> 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.

# Manage Routes with the API

> Create routes and targets, change weights, and roll back with the Divertly API. Includes curl examples and a per-customer route pattern.

Everything you can do in the dashboard you can do over HTTP, so routes can be created by a deploy script, a signup flow, or a job that runs per customer. This guide uses `curl` and `jq`. You'll need an API key (see [Managing API Keys](/docs/organization/managing-api-keys)) and the `CREDENTIAL` variable from [Authentication](/docs/developers/authentication). Remember the [rate limits](/docs/developers/rate-limits-errors).

```bash
API=https://api.divert.ly/v1
AUTH="Authorization: Key $CREDENTIAL"
```

## 1. Find your domain

```bash
curl -s $API/domains -H "$AUTH" | jq '.body[] | {id, name}'
```

Note the `id` of the domain the route will live under. Use `dvt.fyi` if you haven't added your own. Then:

```bash
DOMAIN_ID=<the domain id>
```

## 2. Create a route

```bash
ROUTE_ID=$(curl -s -X POST $API/domains/$DOMAIN_ID/routes \
  -H "$AUTH" -H "Content-Type: application/json" \
  -d '{
    "slug": "acme-download",
    "nickname": "Acme download",
    "description": "Latest installer",
    "enabled": true,
    "targetStrategy": "weighted",
    "targetStrategyFallback": "resolve"
  }' | jq -r '.body.id')
```

The `slug` is the path after the domain. On a shared domain such as `dvt.fyi` it must be unique across all organizations, so prefix it with something of your own. `targetStrategy` can be any strategy your plan includes, and strategies that read a header or query parameter also need `targetStrategySelector`. See [Target Selection](/docs/concepts/target-selection).

## 3. Add targets

A route needs at least one target before it resolves.

```bash
curl -s -X POST $API/domains/$DOMAIN_ID/routes/$ROUTE_ID/targets \
  -H "$AUTH" -H "Content-Type: application/json" \
  -d '{"url": "https://downloads.acme.com/v2/app.zip", "weight": 90, "description": "Current release"}'

NEW_TARGET_ID=$(curl -s -X POST $API/domains/$DOMAIN_ID/routes/$ROUTE_ID/targets \
  -H "$AUTH" -H "Content-Type: application/json" \
  -d '{"url": "https://downloads.acme.com/v3/app.zip", "weight": 10, "description": "Canary"}' \
  | jq -r '.body.id')
```

Target URLs must use `http` or `https`. For non-weighted strategies, set `selectorValue` instead of `weight`. For example, `"selectorValue": "US"` on a Country route.

The link `https://<your-domain>/acme-download` is now live, and roughly 10% of visitors reach the canary.

## 4. Change weights

Update a target by sending only the fields you want to change:

```bash
curl -s -X PUT $API/domains/$DOMAIN_ID/routes/$ROUTE_ID/targets/$NEW_TARGET_ID \
  -H "$AUTH" -H "Content-Type: application/json" \
  -d '{"weight": 50}'
```

The change applies to the next request, with nothing to deploy. Ramp up the new target's weight, and lower the old target's to match, in whatever steps suit you. See [Canary Rollout](/docs/user-guides/canary-rollout) for the approach.

## 5. Roll back

Set the new target's weight back to 0, which sends all traffic to the other target:

```bash
curl -s -X PUT $API/domains/$DOMAIN_ID/routes/$ROUTE_ID/targets/$NEW_TARGET_ID \
  -H "$AUTH" -H "Content-Type: application/json" \
  -d '{"weight": 0}'
```

Or take the target out of rotation entirely by disabling it:

```bash
curl -s -X PUT $API/domains/$DOMAIN_ID/routes/$ROUTE_ID/targets/$NEW_TARGET_ID \
  -H "$AUTH" -H "Content-Type: application/json" \
  -d '{"enabled": false}'
```

Set `"enabled": true` to bring it back. A disabled target keeps its URL and weight.

## One route per customer

Because routes are cheap and unlimited, you can give every customer, tenant, or record its own link. Create the route when the customer is created, and store the returned `id` next to your own record so you can update it later:

```bash
create_customer_route() {
  curl -s -X POST $API/domains/$DOMAIN_ID/routes \
    -H "$AUTH" -H "Content-Type: application/json" \
    -d "{\"slug\": \"acme-$1\", \"nickname\": \"Customer $1\", \"enabled\": true}" \
  | jq -r '.body.id'
}
```

Add a target to each route, and when the customer's destination changes, update that target's `url`. The link you gave them never changes.

## Clean up

```bash
curl -s -X DELETE $API/domains/$DOMAIN_ID/routes/$ROUTE_ID -H "$AUTH"
```

Deleting a route is permanent. To stop one from resolving without deleting it, update it with `{"enabled": false}`.

## Next

* [API Guide](/docs/developers/api-guide): pagination, QR codes, and more.
* [API Reference](/docs/developers/api-reference): every endpoint and field.