CLI authentication
Sign in to productmetrics in a browser, choose the scopes it may use, check the sign-in, and use PM_TOKEN in CI.
productmetrics signs in with your Product Metrics account through the same OAuth server MCP clients use.
There is no API key: you approve the CLI once in a browser, and it stores and renews the tokens itself.
Sign in
# prints the URL, opens the browser, waits up to 5 minutes
productmetrics login
# prints the URL; open it on this machine
productmetrics login --no-browser
# browser on another machine: paste the address it lands on
productmetrics login --paste
# ask for less (default: read,setup,write)
productmetrics login --scopes readThe browser opens the Product Metrics consent page. It names the app (Product Metrics CLI), lists what it Can read and Can change, and you click Connect Product Metrics CLI. Signed out, the button is Continue with Google first. The CLI then stores the tokens for this API origin.
With --paste, the browser lands on a 127.0.0.1 address after you connect. It may not load: copy the full address (or just the code) and paste it into the terminal.
| Flag | What it does |
|---|---|
--scopes <list> | What to allow: read, setup, write (default all three) |
--no-browser | Print the URL without opening a browser |
--paste | Read the redirected address (or the code) from stdin |
--api <origin> | Sign in to another environment, such as https://stage-backend.productmetrics.io |
Scopes
Each API operation needs exactly one scope. The command’s --help names it, and so does productmetrics capabilities.
| Scope | Allows | Examples |
|---|---|---|
read | Reading your setup and data, and sending feedback | productmetrics whoami, productmetrics settings get, productmetrics orders list, productmetrics data query |
setup | Connecting accounts and stores and completing setup steps, including removing connections | productmetrics companies create, productmetrics google-ads create-property-connection, productmetrics stores connect |
write | Changing settings, product rules and feeds, and inviting people | productmetrics settings update, productmetrics product-rules create, productmetrics feed generate, productmetrics invitations send |
A command whose scope your sign-in lacks fails with exit code 3 and a hint with the productmetrics login --scopes command that adds it.
Scopes never widen your role. productmetrics acts as you, with your role in each workspace: an operation that needs a workspace admin still fails for an editor.
Check the sign-in
# which API, signed in or not, scopes, expiry; never calls the API
productmetrics status
# calls the API: your account (email) and properties
productmetrics whoamiproductmetrics status --json returns:
{
"ok": true,
"data": {
"origin": "https://prod-backend.productmetrics.io",
"environment": "production",
"signed_in": true,
"token_source": "stored",
"scope": ["read", "setup", "write"],
"access_token_expires_in_minutes": 42,
"refresh_token": true,
"credentials_file": "/home/you/.config/product-metrics/credentials.json",
"other_signed_in_origins": []
}
}productmetrics whoami --select '.data.properties[].property_id' prints only your property ids, one per line.
Token lifetimes
- Access token: one hour.
productmetricsrenews it with the refresh token when less than a minute is left. - Refresh token: 30 days. If you don’t use
productmetricsfor 30 days, runproductmetrics loginagain.
Your access is checked on every request, so if you lose access to a workspace, productmetrics loses it at once.
CI and scripts: PM_TOKEN
Set PM_TOKEN to an access token and productmetrics uses it instead of the stored sign-in:
PM_TOKEN=<access token> productmetrics whoami --jsonproductmetrics cannot renew a PM_TOKEN: when it expires (after one hour), the API refuses it and productmetrics exits 3 with “PM_TOKEN was refused”.
Where credentials live
${XDG_CONFIG_HOME:-~/.config}/product-metrics/credentials.json, one entry per API origin, file mode 0600 in a 0700 directory. Signing in to stage never replaces your production sign-in.
Sign out
# production
productmetrics logout
# stage
productmetrics logout --api https://stage-backend.productmetrics.ioproductmetrics logout revokes the stored tokens and removes this origin’s entry. It warns when PM_TOKEN is still set in the shell.
Where next
- Commands: which scope each command needs
- For agents: signing in when an agent drives
productmetrics - API overview: the same tokens over HTTP