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 fieldNotes
idYour id for the rule, 1 to 40 characters. Give each rule its own id, because stats report the matched rule by id
nameOptional label, up to 100 characters
conditionsUp to 10 conditions, all of which must match
actionWhere matching scans go

Up to 50 rules per code.

Conditions

kindFieldsMatches when
countryvalues: country codes, e.g. ["US", "CA"]The scan's country is in the list
regionvalues: region codesThe scan's region is in the list
cityvalues: city namesThe scan's city is in the list
devicevalues: any of ios, android, desktop, otherThe device type is in the list
languagevalues: language tags, e.g. ["fr", "pt-BR"]The browser language, or its main part (fr for fr-CA), is in the list
timeOfDayfrom, 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
daysOfWeekvalues: numbers 0 (Sunday) to 6 (Saturday)Today, in the workspace's time zone, is in the list
dateRangefrom, to: optional ISO 8601 timestamps with offsetThe 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

kindFields
redirecturl: an http or https URL
splitvariants: 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.