docs
API

Command line

@affiliaterail/cli: run your affiliate program from a terminal, or let an agent such as Claude Code run it.

A CLI (command-line interface) is a program you run by typing its name in a terminal. affiliaterail (or ar for short) runs your AffiliateRail program that way: list partners, approve commissions, mark payouts paid, run reports. It suits AI agents as much as people. Every answer is JSON, every error says what to do next, and nothing that sends email or changes money runs until a person says yes.

It isn't on npm yet. Until it is, build it from the repository at packages/affiliaterail-cli. The install line below is what it'll be.

npm install -g @affiliaterail/cli

Sign in

Make an API key in the app under Settings, then API keys. Then:

affiliaterail login

It asks for the key, checks it, and saves it in ~/.affiliaterail/config.json, readable only by you. For a script, set AFFILIATERAIL_API_KEY instead. affiliaterail whoami shows which account the next command will use.

A first run

affiliaterail programs list
affiliaterail partners list --program-id prg_123 --limit 10
affiliaterail commissions list --program-id prg_123 --status pending
affiliaterail commissions approve com_123
affiliaterail reports run --program-id prg_123 --dimension partner

Every command is affiliaterail <area> <action>, one for each API operation. A thing in the path is an argument (partners get part_123), and a thing in the query or body is a flag (--status active). affiliaterail <area> --help lists what an area can do.

It asks before it acts

Some commands can't be taken back: sending a campaign, approving or rejecting a commission, changing a commission's amount, re-running commissions through your rules, marking a payout paid, creating a payout batch, recording a sale or a refund, inviting a partner, approving or declining a lead, suspending a flagged partner, rejecting a flag's commissions, crediting a missed sale, and every delete. Before running one, the CLI says what it'll do and waits for a yes. With no person at the keyboard (a script or an agent), it refuses unless you add --yes. So an agent has to come back to you first.

Every POST also sends an idempotency key: a unique string that makes the server do the work once if the same request arrives twice. Pass your own with --idempotency-key when a job might repeat a step.

Reading the answer

  • --pretty prints a table instead of JSON.
  • --fields id,email keeps only those fields.
  • --all on a list reads every page.

Connect an AI app

affiliaterail mcp --config prints the settings that connect an AI app to the AffiliateRail MCP server, for the apps that take a config file. The MCP server shows a confirmation card before every change, in the same spirit as the yes the CLI asks for.

Was this page helpful?