p202 rotator set-rules

Replace a redirector's whole rule set, in the order the rules are tried, in one write

New in 1.9.79Writessupports --staged
All commands

01Jobs it does

Each one is a real command line. Copy it, or open it in the builder below to change it.

redirector rules

Also: rotator rules, rule order, reorder rules, weighted split, split traffic by weight

p202 rotator set-rules <rotator_id>

02What you get

Pick the shape you need. People get a table. Add --json, --csv or --ndjson for scripts, or -q for ids only. An AI agent gets compact JSON without asking. All output formats

03Build your command

Pick values and the command line writes itself, quoted and ready to paste.

p202 rotator set-rules

Set flags below; the command updates as you type.

04Flags

3 flags, plus the global flags every command takes.

FlagWhat it does
--dry-runboolAnswer the set as it would be stored and what would change, and write nothing
--file, -FstringRead the rule set JSON from a file (- for stdin)
--rulesstringThe rule set as JSON: an array of rules as p202 rotator get <id> --json shows them under data.rules, or {"rules": [...]}

05How it works

Sends every rule the redirector is to have to PUT /rotators/{id}/rules, which writes the set in one transaction, as Setup › Redirector saves it: all of it, or nothing. The redirects try the rules in the order given; the first active rule whose criteria all match sends the visitor.

Read the set with p202 rotator get <id> --json (data.rules), change it, and send it back. A rule sent with its id keeps the id (its clicks stay its own), one without an id is added, and a rule left out is removed (the role needs remove_rotator_rule). Each rule needs a rule_name, at least one criterion (value ALL matches everyone) and at least one destination; a rule with more than one destination needs a weight on each, since the redirects split its visitors by weight whatever splittest says. --dry-run answers the set as it would be stored and what would change, writing nothing.

06For agents

Running this from an agent

  • Read the same facts as JSON: p202 commands rotator set-rules --json.
  • With AI_AGENT, CLAUDECODE or another agent variable set, output is compact JSON and errors arrive on stderr as a JSON envelope with a hint.
  • Exit codes: 0 ok, 1 bad input, 2 auth, 3 network, 4 server error, 5 partial failure, 6 no Pro licence on the install.
  • This command writes. Add --staged to record it as a proposal a person applies with p202 change apply.
p202 commands rotator set-rules --json
{
  "path": "p202 rotator set-rules",
  "use": "set-rules <rotator_id>",
  "short": "Replace a redirector's whole rule set, in the order the rules are tried, in one write",
  "long": "Sends every rule the redirector is to have to PUT /rotators/{id}/rules, which writes the set in one\ntransaction, as Setup › Redirector saves it: all of it, or nothing. The redirects try the rules in the\norder given; the first active rule whose criteria all match sends the visitor.\n\nRead the set with `p202 rotator get <id> --json` (data.rules), change it, and send it back. A rule sent\nwith its id keeps the id (its clicks stay its own), one without an id is added, and a rule left out is\nremoved (the role needs remove_rotator_rule). Each rule needs a rule_name, at least one criterion\n(value ALL matches everyone) and at least one destination; a rule with more than one destination needs a\nweight on each, since the redirects split its visitors by weight whatever splittest says. --dry-run answers\nthe set as it would be stored and what would change, writing nothing.",
  "runnable": true,
  "example": "p202 rotator get 3 --json | jq '.data.rules' > rules.json   # edit rules.json, then:\n  p202 rotator set-rules 3 --file rules.json --dry-run\n  p202 rotator set-rules 3 --file rules.json\n  p202 rotator set-rules 3 --rules '[{\"rule_name\":\"Mobile\",\"criteria\":[{\"type\":\"device\",\"value\":\"mobile\"}],\"redirects\":[{\"redirect_campaign\":12}]}]'",
  "tasks": [
    {
      "run": "p202 rotator set-rules",
      "phrases": [
        "redirector rules",
        "rotator rules",
        "rule order",
        "reorder rules",
        "weighted split",
        "split traffic by weight"
      ]
    }
  ],
  "flags": [
    {
      "name": "dry-run",
      "type": "bool",
      "default": "false",
      "usage": "Answer the set as it would be stored and what would change, and write nothing",
      "required": false
    },
    {
      "name": "file",
      "shorthand": "F",
      "type": "string",
      "default": "",
      "usage": "Read the rule set JSON from a file (- for stdin)",
      "required": false
    },
    {
      "name": "rules",
      "type": "string",
      "default": "",
      "usage": "The rule set as JSON: an array of rules as `p202 rotator get <id> --json` shows them under data.rules, or {\"rules\": [...]}",
      "required": false
    }
  ]
}