Redirect rules
Replace a code's redirect rules: geo, device, language and time targeting, and A/B splits.
Plan: Pro and up (redirect rules).
PUT /api/v1/codes/{id}/rules
Replaces all rules on the code with the list you send. Read the current list first with GET /codes/{id}. Send {"rules": []} to remove every rule.
Rules run top to bottom. A rule matches when all of its conditions match, and a rule with no conditions always matches. The first matching rule decides where the scan goes, and scans that match no rule go to the code's normal destination.
Body
{
"rules": [
{
"id": "uk-ios",
"name": "UK iPhone users",
"conditions": [
{ "kind": "country", "values": ["GB"] },
{ "kind": "device", "values": ["ios"] }
],
"action": { "kind": "redirect", "url": "https://apps.apple.com/gb/app/example/id123" }
},
{
"id": "ab-test",
"name": "Landing page test",
"conditions": [],
"action": {
"kind": "split",
"variants": [
{ "id": "a", "url": "https://example.com/landing-a", "weight": 50 },
{ "id": "b", "url": "https://example.com/landing-b", "weight": 50 }
]
}
}
]
}
| Rule field | Notes |
|---|---|
id | Your id for the rule, 1 to 40 characters. Give each rule its own id, because stats report the matched rule by id |
name | Optional label, up to 100 characters |
conditions | Up to 10 conditions, all of which must match |
action | Where matching scans go |
Up to 50 rules per code.
Conditions
kind | Fields | Matches when |
|---|---|---|
country | values: country codes, e.g. ["US", "CA"] | The scan's country is in the list |
region | values: region codes | The scan's region is in the list |
city | values: city names | The scan's city is in the list |
device | values: any of ios, android, desktop, other | The device type is in the list |
language | values: language tags, e.g. ["fr", "pt-BR"] | The browser language, or its main part (fr for fr-CA), is in the list |
timeOfDay | from, to: "HH:MM" | The time in the workspace's time zone is from from up to to. If from is later than to, the window crosses midnight |
daysOfWeek | values: numbers 0 (Sunday) to 6 (Saturday) | Today, in the workspace's time zone, is in the list |
dateRange | from, to: optional ISO 8601 timestamps with offset | The scan is on or after from and before to |
Country, region, city and language values are case-insensitive. Each list holds 1 to 250 values.
Actions
kind | Fields |
|---|---|
redirect | url: an http or https URL |
split | variants: 2 to 10 items { "id", "url", "weight" }. Weights are whole numbers that add up to 100 |
Response
The updated code object with rules, in data.
The destinations go through the same safety checks as the code's main URL. On Starter, every call to this endpoint returns 402 PLAN_FEATURE, even with an empty list. If a workspace drops below Pro, its saved rules are kept but stop running until it upgrades again.