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

# Create a route

POST https://api-dev.divert.ly/v1/domains/{domain_id}/routes
Content-Type: application/json

Defines a path on the domain. A route needs at least one target before it resolves.

Reference: https://docs.divert.ly/api-reference/divertly-api/routes/create-route

## Authentication

- `Authorization` header (required) — API key credential, sent as `Key <base64(keyId:secret)>`.

## Servers

- `https://api-dev.divert.ly` (Development, default)
- `https://api.divert.ly` (Production)

## Request

### Path parameters

- `domain_id` (string, required)

### Body (application/json)

This endpoint expects a NewRoutePostObject.

- `nickname` (string, required)
- `slug` (string, required) — Path segment the route is served at.
- `description` (string, optional)
- `enabled` (boolean, optional)
- `targetStrategy` (enum, optional)
  - Allowed values: `browser_make`, `country`, `device_type`, `header`, `human`, `ip_cidr`, `language`, `os`, `query_string`, `random`, `user_agent`, `weighted`
- `targetStrategyFallback` (enum, optional) — What to do when no target matches.
  - Allowed values: `error`, `resolve`
- `targetStrategySelector` (string, optional) — The visitor attribute the strategy selects on.

## Response

### 201

Created

- `body` (Route, optional)

## Errors

### 400 Bad Request Error

Bad Request - malformed or failed validation

- `error` (string, optional, nullable)
- `meta` (ErrorResponseMeta, optional, nullable)

### 401 Unauthorized Error

Unauthorized - missing, malformed or rejected credentials

- `error` (string, optional, nullable)
- `meta` (ErrorResponseMeta, optional, nullable)

### 403 Forbidden Error

Forbidden - the principal is not permitted to make this request

- `error` (string, optional, nullable)
- `meta` (ErrorResponseMeta, optional, nullable)

### 404 Not Found Error

Not Found - no such resource

- `error` (string, optional, nullable)
- `meta` (ErrorResponseMeta, optional, nullable)

### 429 Too Many Requests Error

Too Many Requests - per-principal rate limit exceeded

- `error` (string, optional, nullable)
- `meta` (ErrorResponseMeta, optional, nullable)

### 500 Internal Server Error

Internal Server Error

- `error` (string, optional, nullable)
- `meta` (ErrorResponseMeta, optional, nullable)

## Types

### Route

- `createdAt` (datetime, optional)
- `defaultTargetId` (string, optional, nullable)
- `description` (string, optional)
- `domainId` (string, optional)
- `domainRisk` (RouteDomainRisk, optional, nullable)
- `enabled` (boolean, optional)
- `id` (string, optional)
- `nickname` (string, optional)
- `organizationId` (string, optional)
- `risk` (RouteRisk, optional, nullable)
- `slug` (string, optional)
- `sticky` (boolean, optional)
- `targetStrategy` (enum, optional)
  - Allowed values: `browser_make`, `country`, `device_type`, `header`, `human`, `ip_cidr`, `language`, `os`, `query_string`, `random`, `user_agent`, `weighted`
- `targetStrategyFallback` (enum, optional)
  - Allowed values: `error`, `resolve`
- `targetStrategySelector` (string, optional)
- `updatedAt` (datetime, optional)
- `urn` (string, optional)

### ErrorResponseMeta

- `errorCode` (enum, optional)
  - Allowed values: `E1000`, `E1001`, `E1002`, `E1003`, `E1010`, `E1020`, `E1030`, `E1035`, `E1036`, `E1040`, `E1060`, `E1070`, `E1080`, `E1082`, `E1083`, `E1090`, `E1100`, `E1110`, `E1120`, `E1130`, `E1140`, `E1150`, `E1160`, `E1170`, `E1171`, `E1180`, `E1190`, `E1200`, `E1210`, `E1220`, `E1230`, `E1231`, `E1240`, `E1250`, `E1260`, `E1270`, `E1280`, `E1290`, `E1300`, `E1310`, `E1320`, `E1325`, `E1330`, `E1335`, `E1340`, `E1350`, `E1360`, `E1365`, `E1370`, `E1380`, `E1390`, `E1395`, `E1400`, `E1410`, `E1420`, `E1430`, `E1440`, `E1450`, `E1460`, `E1470`, `E1480`, `E1490`, `E1500`, `E1510`, `E1520`, `E1530`, `E1540`, `E1550`, `E1560`, `E1570`, `E1571`, `E1580`, `E1590`, `E1600`, `E1610`, `E1620`, `E1630`, `E1636`, `E1640`, `E1650`, `E1660`, `E1670`, `E1680`, `E1690`, `E1700`, `E1710`, `E1720`, `E1730`, `E1740`, `E1750`, `E1800`, `E1801`, `E1802`, `E1810`, `E1820`, `E1830`, `E1850`, `E1900`, `E1950`, `E2000`, `E2100`, `E2110`, `E2120`, `E2130`, `E2140`, `E2150`, `E2160`, `E2170`, `E2180`, `E3190`, `E3200`, `E3210`, `E3220`, `E3230`, `E3240`, `E3250`, `E3300`, `E3310`, `E3400`, `E3410`, `E3420`, `E3430`, `E3440`, `E3450`, `E3460`, `E3470`, `E3480`, `E3490`, `E3510`, `E3520`, `E3530`, `E3540`, `E3550`, `E3560`, `E3570`, `E3580`

### RouteDomainRisk

- `lastCheckedAt` (datetime, optional, nullable)
- `reason` (string, optional, nullable)
- `score` (long, optional)
- `status` (enum, optional)
  - Allowed values: `unknown`, `pending`, `clean`, `flagged`
- `thresholdAtCheck` (long, optional)

### RouteRisk

- `lastCheckedAt` (datetime, optional, nullable)
- `reason` (string, optional, nullable)
- `score` (long, optional)
- `status` (enum, optional)
  - Allowed values: `unknown`, `pending`, `clean`, `flagged`
- `thresholdAtCheck` (long, optional)

## Examples

**Request**

```json
{
  "nickname": "Spring campaign",
  "slug": "spring"
}
```

**Response**

```json
{
  "body": {
    "createdAt": "2024-01-15T09:30:00Z",
    "defaultTargetId": "string",
    "description": "string",
    "domainId": "string",
    "domainRisk": {
      "lastCheckedAt": "2024-01-15T09:30:00Z",
      "reason": "string",
      "score": 1,
      "status": "unknown",
      "thresholdAtCheck": 1
    },
    "enabled": true,
    "id": "string",
    "nickname": "string",
    "organizationId": "string",
    "risk": {
      "lastCheckedAt": "2024-01-15T09:30:00Z",
      "reason": "string",
      "score": 1,
      "status": "unknown",
      "thresholdAtCheck": 1
    },
    "slug": "string",
    "sticky": true,
    "targetStrategy": "browser_make",
    "targetStrategyFallback": "error",
    "targetStrategySelector": "string",
    "updatedAt": "2024-01-15T09:30:00Z",
    "urn": "string"
  }
}
```

**SDK Code**

```python
import requests

url = "https://api-dev.divert.ly/v1/domains/domain_id/routes"

payload = {
    "nickname": "Spring campaign",
    "slug": "spring"
}
headers = {
    "Authorization": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api-dev.divert.ly/v1/domains/domain_id/routes';
const options = {
  method: 'POST',
  headers: {Authorization: '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"nickname":"Spring campaign","slug":"spring"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api-dev.divert.ly/v1/domains/domain_id/routes"

	payload := strings.NewReader("{\n  \"nickname\": \"Spring campaign\",\n  \"slug\": \"spring\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api-dev.divert.ly/v1/domains/domain_id/routes")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"nickname\": \"Spring campaign\",\n  \"slug\": \"spring\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api-dev.divert.ly/v1/domains/domain_id/routes")
  .header("Authorization", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"nickname\": \"Spring campaign\",\n  \"slug\": \"spring\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api-dev.divert.ly/v1/domains/domain_id/routes', [
  'body' => '{
  "nickname": "Spring campaign",
  "slug": "spring"
}',
  'headers' => [
    'Authorization' => '<apiKey>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api-dev.divert.ly/v1/domains/domain_id/routes");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"nickname\": \"Spring campaign\",\n  \"slug\": \"spring\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "nickname": "Spring campaign",
  "slug": "spring"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api-dev.divert.ly/v1/domains/domain_id/routes")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```