Purchasely in your terminal

The command line tool for the Purchasely Management API. Manage apps, placements and experiments from your terminal, CI pipeline or coding agent.

curl -fsSL https://cli.purchasely.io/install.sh | sh

macOS and Linux. Needs Node 20 or later.

$ purchasely search "list placements"
[
  {
    "command": "purchasely placements list --app app_xxx",
    "summary": "List placements for an application",
    "method": "GET",
    "path": "/management/v1/applications/{application_id}/placements",
    "scope": "targeting.placements:view"
  },
  …
]
$ purchasely placements list --app app_xxx

Install

One command installs the CLI under ~/.local/share/purchasely/install and links purchasely into ~/.local/bin or ~/bin. Node 20 or later must be installed first.

  1. Run the installer

    curl -fsSL https://cli.purchasely.io/install.sh | sh

    It downloads the latest version and checks its checksum. It uses ~/.local/bin or ~/bin if one of them is already on your PATH. Else it creates ~/.local/bin and adds one line to your shell profile: ~/.zshrc for zsh, ~/.bashrc and ~/.bash_profile for bash, ~/.profile for other shells. It never uses sudo.

    Open a new terminal if the command is not found.

  2. Log in with a Management API key

    purchasely auth login

    Create the key in the Purchasely Console, from the account menu, in Management API keys. It is not the SDK API key of your app. The CLI asks for the key with a hidden prompt and stores it in the macOS keychain, or in a file only you can read on Linux.

    purchasely auth status shows where the key comes from and its last 4 characters. It does not test API access.

  3. Read your first data

    purchasely apps list --output table

    It prints your applications with their ids. Use an id as --app in every Management command. In CI, set PURCHASELY_API_KEY as a secret instead of logging in.

Uninstall

Remove the install folder and the purchasely link in your bin folder. command -v purchasely shows the link.

rm -rf ~/.local/share/purchasely/install
rm "$(command -v purchasely)"

Examples

Replace app_xxx and the other ids with your own. purchasely apps list gives your application ids.

List the placements of an app

purchasely placements list \
  --app app_xxx \
  --fields id,vendor_id \
  | jq -r '.placements[]
      | "\(.id) \(.vendor_id)"'

The pipe requires jq. Without --app, the command lists the placements of all your apps.

Show one placement

purchasely placements get \
  --app app_xxx --id plc_xxx \
  --output table

A read: it changes nothing and needs no --env.

Rename a placement

Look at the request first. The dry run sends nothing.

purchasely placements update \
  --app app_xxx --id plc_xxx \
  --data '{"name":"Onboarding"}' \
  --env staging --dry-run

Then send it.

purchasely placements update \
  --app app_xxx --id plc_xxx \
  --data '{"name":"Onboarding"}' \
  --env staging

Every resource of the Management API

The commands are built from the Management API spec. When the API gets a new endpoint, the CLI gets a new command. The pattern is always purchasely <resource> <action>.

Screen commands manage metadata. They do not return screen layout JSON.

Apps and catalog

  • applications
  • platforms
  • products
  • plans
  • distributions
  • subscriptions
  • one-time-purchases
  • users

Screens and targeting

  • screens
  • screen-versions
  • placements
  • audiences
  • campaigns
  • flows
  • web-flows
  • web-activations
  • fonts
  • translations
  • category-tags

Events and integrations

  • custom-events
  • custom-event-properties
  • custom-properties
  • webhooks
  • webhook-deliveries
  • client-errors

Experiments and surveys

  • ab-tests
  • surveys
  • answers

Analytics

  • dashboard
  • dashboard summary
JSON you can pipe
The response goes to stdout as JSON, ready for jq. Errors go to stderr as one JSON object. Add --output table to read a list yourself. An answer over 200 KB goes to a file and the CLI prints its path.
A dashboard in your terminal
purchasely dashboard summary --app app_xxx --output table shows the MRR, active subscriptions, paywall viewers and conversions of an app, with a sparkline per metric. Without --output table, the same numbers come as JSON.
Find a command in plain words
purchasely search "start an a/b test" returns the best matching commands. --help on a command shows its scope, path, options and an example.
The full command reference
Every command, option and example is on the CLI reference page, and in man purchasely. Agents read it as JSON with purchasely reference --format json.
Raw API calls
purchasely api GET /applications calls any Management endpoint with your key, under the same rules: the limiter, --dry-run, --env on a write and the confirmation.
Shell completion
source <(purchasely completion zsh) in your ~/.zshrc completes the commands and the options. Bash and fish work too.
A break between two deploys
purchasely games opens six terminal games: 2048, invaders, minesweeper, pong, snake and tetris. They use no key and send no request.
A dry run on every write
--dry-run prints the method, URL, headers and body, and sends nothing. The key shows as <redacted>. It works without a key.
Explicit environment
--env prod or --env staging. Reads use prod by default. A write without --env is refused, also with --dry-run.
Confirmation for destructive changes
When the API asks for a confirmation, for example to delete a placement in use, the CLI shows the impact. In a terminal, it asks you first. --yes confirms. In a script, it stops with exit code 8 and gives a token that you can send back with --confirm-token within 5 minutes.
Rate limits handled for you
The API allows 60 requests and 10 writes per minute per key. A built-in limiter, shared by all CLI processes on your machine, stays under it. On a 429, the CLI waits for the time the server gives and slows down.
API key handling
The key is never printed. Status shows its last 4 characters, the dry run hides it, and the usage log on your machine keeps no key and no query value.
What the CLI sends

Management commands go to api.purchasely.io, or api-staging.purchasely.io with --env staging, with your key. The User-Agent header carries the CLI version and your --reason value.

Once a day, the CLI asks cli.purchasely.io for the latest version and downloads it from there. purchasely ai downloads the public Purchasely AI plugin from GitHub.

Exit codes for scripts
Exit codes
0Success
1Generic error, network error, server error
2Usage error: bad flag or bad JSON in --data
3No key, or key not accepted
4Forbidden: missing scope or feature
5Validation failed
6Not found
7Rate limited: stop and wait
8Confirmation required and not given
10Write refused: --env missing

Made for coding agents

Claude Code, Codex and other agents can drive the CLI safely. Give them these rules.

  1. Find the command with purchasely search "<task>". The first result is the best match.
  2. Read the help of that one command: purchasely <resource> <action> --help.
  3. Read the JSON on stdout and the exit code.
  4. Run --dry-run before every write and show the request to the user. Use --env staging unless the user says prod.
  5. Never pass --yes without the approval of the user.

Give the agent the key through PURCHASELY_API_KEY or purchasely auth login. Never put the key in a command.

# User: rename the onboarding placement on staging
$ purchasely search "update a placement"
[
  {
    "command": "purchasely placements update --app app_xxx --id <id> --data @body.json --env prod",
    "method": "PATCH",
    …
  }
]
$ purchasely placements update --help
$ purchasely placements update --app app_xxx --id plc_xxx \
    --data '{"name":"Onboarding"}' --env staging --dry-run
{
  "method": "PATCH",
  "url": "https://api-staging.purchasely.io/management/v1/applications/app_xxx/placements/plc_xxx",
  "headers": {
    "Authorization": "Bearer <redacted>",
    "Accept": "application/json",
    "User-Agent": "purchasely-cli/<version> (-; -)",
    "Content-Type": "application/json"
  },
  "body": {
    "name": "Onboarding"
  }
}
# Agent: this is the request. Send it?
# User: yes
$ purchasely placements update --app app_xxx --id plc_xxx \
    --data '{"name":"Onboarding"}' --env staging

The Purchasely AI plugin

The rules above make the CLI safe for any agent. The plugin adds Purchasely knowledge to the agent: SDK integration, review, debug and migration.

One command

purchasely ai install
  1. It finds Claude Code, Codex, Copilot CLI, Gemini CLI, Cursor and OpenCode on your machine. Use --agent to choose one.
  2. purchasely ai status shows the agents and the plugin version. purchasely ai update and purchasely ai uninstall change only what ai install registered.
  3. The CLI also updates the plugin once a day in the background, only in those agents.

6 skills

purchasely-cli, sdk-expert, integrate, review, debug and migrate.

Ask the agent to integrate the SDK with your real placements, products, plans and custom events, read by the CLI from your account. Ask it to debug, review or improve your integration.

The CLI does not return the SDK API key of an app. Copy it from the Console (App settings) into your app configuration. The agent does not ask for it.

Updates

The CLI keeps itself up to date. You do not need to run the installer again.

Automatic

Once a day, the CLI checks for a new version in the background. It downloads and installs it in a separate process, so your command does not wait. The new version is used on the next run.

Now

purchasely update

Checks and installs the latest version at once.

Off

export PURCHASELY_DISABLE_AUTOUPDATE=1

The automatic check also stays off when the CI variable is set, so a pipeline always runs the version it installed.