Manage virtual currencies from the CLI

The Adapty CLI manages virtual currencies from the terminal, under the adapty virtual-currencies topic. You can list the currencies of an app, create a currency, change its name and description, and add, change, or remove its mappings: the linked products of the currency, with the credits each one grants. You can also read the credit transactions of an app or of one user, and the balances of one user. The CLI output calls credits coins.

Use it to let an AI agent set up your currencies, or to find out why a user has a balance without opening the dashboard. The currency and mapping commands do what the Virtual currency tab of the Products page does. The transaction and balance reads show the same data as the user’s profile in the dashboard, but they don’t change a balance. To correct one, adjust it in the dashboard.

Before you start

The virtual-currencies topic uses the same installation and login as the rest of the CLI. If you have not set that up, follow steps 1 and 2 of the quickstart guide. To see whether your CLI has the topic, run:

adapty virtual-currencies --help

Every command takes the app’s UUID in --app. To find it, run:

adapty apps list

A mapping names a product by its Adapty product ID, not by its store product ID. To find the product IDs, run:

adapty products list --app <app-id>

List and read currencies

adapty virtual-currencies list --app <app-id>

The list shows each currency with its code, name, and the number of products that grant it. It takes --page and --page-size, as the other lists of the CLI do.

To read one currency with all its mappings, run:

adapty virtual-currencies get <currency-id> --app <app-id>

The currency has these fields:

FieldValue
virtual_currency_idThe ID of the currency. The other commands take it as their argument.
codeThe code that the server-side API, the SDK, and the analytics filter use. You can’t change it.
name, descriptionThe display name and the optional description.
products_countThe number of products that grant the currency.
updated_atThe time of the last change, in milliseconds. Send it in --expected-updated-at, as Protection against lost changes describes.
mappingsOnly in get: the products that grant the currency, with the credits of each product.

A mapping sets how many credits one product grants:

  • one-time: credit_per_purchase credits for each purchase of the product.
  • subscription: credit_per_cycle credits for each paid period. expiring: true makes the credits of a period expire when the subscription renews or ends. credit_on_trial_start gives the credits of a trial start, or null for none.

A mapping grants credits from the next purchase or renewal of its product, in production and in sandbox. Current subscribers get them at their next renewal. To give credits to existing users now, grant a balance through the server-side API. For what each setting does, see Create a virtual currency.

Create a currency

Warning

You can’t delete a currency or change its code. An app can have up to 20 currencies.

adapty virtual-currencies create --app <app-id> --code GEMS --name "Gems" \
  --description "Spent on hints" --file mappings.json

--code takes letters, digits, and _, up to 32 characters, and it must be unique in the app. The CLI keeps the letter case as you type it, unlike the dashboard, which makes codes uppercase: gems and GEMS are two different codes. To match the currencies you create in the dashboard, use uppercase. The server-side API and the transaction and analytics filters need the code in the same case. --name takes up to 64 characters, and --description up to 256. --file is optional: without it, the currency has no mappings.

The mappings file is a JSON list. Each item is a full mapping:

[
  {
    "product_id": "<one-time-product-id>",
    "product_type": "one-time",
    "credit_per_purchase": 100
  },
  {
    "product_id": "<subscription-product-id>",
    "product_type": "subscription",
    "credit_per_cycle": 500,
    "expiring": true,
    "credit_on_trial_start": 50
  }
]

In create, you can leave out credit_on_trial_start: a trial then grants no credits. The CLI checks the file before it sends anything. If the file isn’t a JSON list with at least one item, the CLI exits with code 2.

Before it creates the currency, the CLI shows the code, the mapped products, and that you can’t delete the currency or change its code. It then asks for approval, as described in Confirmation in scripts and agents.

Change the name or the description

adapty virtual-currencies update <currency-id> --app <app-id> --name "Gold gems"

Give at least one of --name, --description, and --clear-description. A value that you don’t give stays as it is: the CLI reads the currency first and sends its current value. --clear-description removes the description. You can’t use it together with --description.

update doesn’t ask for approval, because a second update reverts it.

Add or change mappings

adapty virtual-currencies mappings upsert <currency-id> --app <app-id> --file mappings.json

The file has the form of the create file, with 1 to 200 items. A currency has at most 200 mappings in total. Each item replaces the mapping of its product, or adds a mapping for a product that has none. Give every field of each item, also credit_on_trial_start (null for none). Adapty doesn’t merge an item with the current mapping: it refuses an item with a missing or unknown field with exit code 4, and nothing changes. A mapping that the file doesn’t name stays as it is. mappings upsert never removes a mapping.

Before it sends the change, the CLI reads the currency and shows each product that changes:

  • A new mapping: new and its credits.
  • A changed mapping: the credits before and after, for example 30 → 50 for each purchase or each period. A change of expiring or credit_on_trial_start shows its value before and after too. The product_type of an item must be the type of its product: Adapty refuses a mapping whose product_type changes, with exit code 4.

Remove a mapping

adapty virtual-currencies mappings delete <currency-id> --app <app-id> --product <product-id>

After the delete, purchases of the product grant no credits of this currency, and Adapty writes no transaction for them. Credits that the product already granted stay in your users’ balances. If the product has no mapping, Adapty answers with a 404 error and exit code 4.

Read credit transactions

To read the credit transactions of an app, run:

adapty virtual-currencies transactions list --app <app-id> \
  --date-from 2026-11-01 --date-to 2026-11-07 --timezone Europe/Berlin

The period is required, at most 366 days, both days included. The days are days of --timezone, an IANA time zone name, or of the app time zone without it. Filter the transactions with --currency-code, --operation, --feature, and --sandbox or --no-sandbox. For the operation values, see Operation.

To read the transactions of one user, name the user by exactly one of --profile, the Adapty profile ID, and --customer-user-id, your own user ID:

adapty virtual-currencies profiles transactions list --app <app-id> --customer-user-id <user-id>

The period of a user’s transactions is optional. Without it, the CLI reads the whole history of the user. It takes the same filters and --timezone.

The transactions come newest first, one page for each command. A page has 20 transactions by default, and --page-size sets 1 to 100. When the period has more transactions, the table ends with More rows: and the command for the next page: the same flags and --cursor with the cursor of this page. Run the next page with the same period, filters, and time zone. A cursor with other filters fails with the cursor_filters_mismatch error. With --json, the output is the answer of Adapty as it is, data and meta, and the cursor is meta.pagination.next_cursor.

The CLI has no option to read all pages. To load every transaction into your data warehouse, use the daily export to Amazon S3 or Google Cloud Storage.

Note

For totals and trends, use the virtual currency charts of adapty analytics, not a sum of transactions. To find the chart names, run adapty analytics catalog. A chart leaves out each user with a sandbox transaction, and the transaction list doesn’t. So a sum of transactions can differ from a chart.

Read the balances of a user

adapty virtual-currencies profiles balances get --app <app-id> --profile <profile-id>

Name the user by exactly one of --profile and --customer-user-id. The balances show each currency of the user with its balance, the held and available credits, and the expiry breakdown: the credits that don’t expire, the credits that expire soonest with their expiry times, the sum of the credits that expire later, and the expired credits.

To find out why a user has a balance, read the user’s transactions and the balances together. The dashboard shows the same data on the user’s profile.

Protection against lost changes

Someone can change the currency in the dashboard, or another agent can change it, between your read and your write. To keep that change, mappings upsert and mappings delete send expected_updated_at, the updated_at of the currency that you read. If the currency changed after that read, Adapty refuses the write with the virtual_currency_conflict error, exit code 4, and changes nothing. Read the currency again, and decide again.

How the command runsThe expected_updated_at that the CLI sends
With --yesThe value of --expected-updated-at. Without the flag, the CLI sends nothing and exits with code 6.
In a terminal, with --expected-updated-atThe value of the flag, after you answer y.
In a terminal, without --expected-updated-atThe updated_at of the CLI’s own read, after you answer y.

A script reads updated_at with get --json and passes it after approval:

updated_at=$(adapty virtual-currencies get <currency-id> --app <app-id> --json | jq .updated_at)
# Show the change to the person who approves it. After their yes:
adapty virtual-currencies mappings upsert <currency-id> --app <app-id> \
  --file mappings.json --yes --expected-updated-at "$updated_at"

Confirmation in scripts and agents

These commands show their effect and ask for approval before they send the change:

  • create
  • mappings upsert
  • mappings delete

How they ask depends on how the command runs:

How the command runsWhat happens
In a terminal, without --yes and without --jsonThe CLI shows the effect and asks Apply? [y/N]. If you answer y or yes, the CLI sends the request. For any other answer, the CLI exits with code 1 and sends nothing.
With --yesThe CLI sends the request without asking. Mapping writes also need --expected-updated-at.
Without --yes, with --json, in a pipe, or with no terminalThe CLI sends nothing and exits with code 6. The error shows the effect.

A script reads updated_at with get --json, shows the change, and runs the command with --yes --expected-updated-at after approval. An agent can also run the command without --yes and show the effect from the error.

list, get, update, and the transaction and balance reads run without asking.

Errors

Exit codeCauseWhat to do
1You answered something other than y or yes at the prompt. Nothing was sent.Run the command again if you meant to.
2The CLI refused the input before it sent anything: a flag, a mappings file that isn’t a JSON list with at least one item, update without a change, --description with --clear-description, or both or neither of --profile and --customer-user-id.Fix what the error names.
3You aren’t logged in, or Adapty refused access with HTTP status 403: the app belongs to another account, or your sign-in can read the app but not change it. With --json, the error gives status: 403.Log in with adapty auth login, and find the app ID in adapty apps list. If reads work and writes fail, ask an account owner for access that can make changes.
4Adapty refused the request. The error gives the reason, and --json gives the HTTP status and error_code. A server error (5xx) on a write also gives code 4, and the result is unknown.See Messages from Adapty. After a server error on a write, see If a write gets no answer.
5The CLI couldn’t reach Adapty.Make sure you are online. After a write, see If a write gets no answer.
6A command that asks for approval ran without --yes and with no one to answer, or a mapping write ran with --yes and without --expected-updated-at. Nothing was sent.Show the effect in the error to the person who approves the change. After that person approves it, run the command again as Protection against lost changes describes.
130You pressed Ctrl+C at the prompt. Nothing was sent.—

Messages from Adapty

With --json, the error gives the error_code:

error_codeCauseWhat to do
virtual_currency_conflictThe currency changed after the read whose updated_at the write sent. Nothing changed.Read the currency with get, and decide again.
invalid_date_rangeThe period of transactions list is longer than 366 days, or the period of a transaction list ends before it starts.Use a shorter period, or give a --date-from that isn’t after --date-to.
cursor_filters_mismatchThe cursor belongs to a page with another period, other filters, or another time zone.Run the next page with the same flags as the first page.
invalid_cursorThe value of --cursor isn’t a cursor from Adapty.Copy the cursor from the More rows: line, or from meta.pagination.next_cursor.
profile_does_not_existThe app has no user with this profile ID or customer user ID. A deleted user can’t be found by the customer user ID.Make sure that the ID is correct. For a deleted user, use --profile.
throttledMore than 2 calls of the same transaction or balance read in one second for the same app.Wait and run the command again. The CLI waits and tries a read up to 3 times.

Adapty also refuses a 21st currency in an app and a code that the app already uses, with exit code 4.

If a write gets no answer

If the CLI gets no answer to a write, because of a network error or a server error (exit code 4 or 5), it can’t tell whether Adapty saved the change. The CLI doesn’t send the write again. Before you run the command again, read what Adapty saved: after create, run list and look for the code. After any other write, read the currency with get. A second write can fail although the first one passed: with virtual_currency_conflict, with a 404 for a mapping that is already removed, or with a used code after a create.

Command reference

Every command takes --app, the app UUID from adapty apps list. The commands that take <currency-id> take the virtual_currency_id from list.

virtual-currencies list

FlagRequiredDescription
--pageNoPage number. Default: 1.
--page-sizeNoCurrencies per page, up to 100. Default: 20.

virtual-currencies get

Takes the currency ID as its argument. Returns the currency with all its mappings.

virtual-currencies create

FlagRequiredDescription
--codeYesThe code of the currency. You can’t change it later.
--nameYesThe display name.
--descriptionNoThe description.
--fileNoThe JSON file of the mappings. See Create a currency.
--yes, -yNoCreate without asking. Required with --json or in a pipe.

virtual-currencies update

Takes the currency ID as its argument.

FlagRequiredDescription
--nameNoThe new display name.
--descriptionNoThe new description.
--clear-descriptionNoRemove the description.

virtual-currencies mappings upsert

Takes the currency ID as its argument.

FlagRequiredDescription
--fileYesThe JSON file of 1 to 200 full mappings. See Add or change mappings.
--expected-updated-atWith --yesThe updated_at of the read that the change is based on.
--yes, -yNoChange without asking. Required with --json or in a pipe.

virtual-currencies mappings delete

Takes the currency ID as its argument.

FlagRequiredDescription
--productYesThe Adapty product ID of the mapping to remove.
--expected-updated-atWith --yesThe updated_at of the read that the change is based on.
--yes, -yNoRemove without asking. Required with --json or in a pipe.

virtual-currencies transactions list

FlagRequiredDescription
--date-from, --date-toYesThe first and the last day, YYYY-MM-DD, at most 366 days.
--timezoneNoThe IANA time zone of the days. Default: the app time zone.
--currency-codeNoOnly transactions of this currency.
--operationNoOnly transactions with this operation.
--featureNoOnly transactions with this feature.
--sandbox, --no-sandboxNo--sandbox for sandbox transactions only, --no-sandbox for production only. Default: both.
--page-sizeNoTransactions per page, 1 to 100. Default: 20.
--cursorNoThe cursor of the next page, from the previous page.

virtual-currencies profiles transactions list

Takes exactly one of --profile and --customer-user-id, and the flags of transactions list. The period is optional.

FlagRequiredDescription
--profileOne of the twoThe Adapty profile ID of the user.
--customer-user-idOne of the twoYour own ID of the user.

virtual-currencies profiles balances get

FlagRequiredDescription
--profileOne of the twoThe Adapty profile ID of the user.
--customer-user-idOne of the twoYour own ID of the user.

Work from an AI assistant

The Adapty MCP server offers the same actions as virtual_currencies_* tools, for example virtual_currencies_mappings_upsert for mappings upsert. The tools work the same way as the commands, with these differences:

  • Protection against lost changes: virtual_currencies_update, virtual_currencies_mappings_upsert, and virtual_currencies_mappings_delete require expected_updated_at, the updated_at of a read. After a virtual_currency_conflict error, the assistant reads the currency again.
  • Description: In virtual_currencies_update, an empty description removes the description.
  • Pages: When meta.pagination.has_more is true, the assistant sends meta.pagination.next_cursor in cursor, with the same filters and time zone, for the next page.
  • Approval: The tools don’t ask for approval and have no --yes. Before virtual_currencies_create, virtual_currencies_mappings_upsert, and virtual_currencies_mappings_delete, the assistant shows you the change and waits for your yes.
  • Throttling: After a throttled error, the tools don’t try the read again. The error says how long to wait.

What’s next