Skip to content

Generate accounts and vouchers with patterns

When you sell prepaid cards or vouchers, you need hundreds of records with unique, random numbers and PINs. Instead of preparing them in a spreadsheet, you put a pattern in a field and let the switch fill it with a new random value for every record. This tutorial generates a batch of top-up vouchers in the panel and shows the same patterns for accounts created through the API. Allow 10 minutes.

  • You have Administrator access to the panel, with the right to add top-up vouchers.
  • You know the value, currency and expiration date of the batch.

A field contains either a fixed value or exactly one pattern. A pattern cannot be combined with fixed text in the same field.

Pattern Generates Example Result
${N:n} n random digits; the first digit is never 0 ${N:10} 4093817265
${N:[…][…]…} One digit per bracket: a range [0-6], a list [0,4,9] or a fixed digit [5] ${N:[2,3,4][0-8][0-9][0-9]} 2000–2899, 3000–3899 or 4000–4899
${P:n} A random password of n letters and digits, with at least one digit ${P:12} k3XbQ9pLm2Ra
${C:Field} A copy of the value generated for another field of the same record ${C:Account Name} The same value as Account Name

To start every number with a fixed prefix, give each prefix digit its own bracket: ${N:[7][7][0-9][0-9][0-9][0-9][0-9][0-9]} gives eight-digit numbers that start with 77.

  1. Open Payments → Top-Up Vouchers.
  2. Click Generate.
  3. Keep or change Voucher ID. The default ${N:[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]} gives ten random digits.
  4. Enter Book Value, select Currency and set Expiration Date and Credit Lifetime, days.
  5. Enter a Batch Tag, for example promo-2026-11, to find the batch later.
  6. Select Use Secret PIN if the customer must enter a PIN as well, and keep or change the Secret PIN pattern. The default gives four random digits.
  7. Enter Number of Top-up Vouchers, from 1 to 10000.
  8. Click Generate.
Screenshot "tutorials/vouchers-generate" has not been generated yet — see scripts/screenshots/screens.yml.

Result: the browser downloads a Top-up Vouchers file with one row per voucher, including the generated Voucher ID and Secret PIN. The vouchers appear in the list with the batch tag.

createAccount of the XML-RPC API accepts the same patterns in its parameters and returns the generated credentials. Call it once per card, for example from a script:

request
call("createAccount", {
"username": "${N:[1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]}",
"authname": "${C:username}",
"voip_password": "${N:[0-9][0-9][0-9][0-9]}",
"web_password": "${P:12}",
# … the other required parameters of createAccount
})

In the API, ${C:…} takes the name of another parameter, not a panel label. See Creating accounts for the other parameters. To load accounts from a file instead, use Upload… on the Accounts screen; the file takes fixed values only. See Accounts.

  1. Open Payments → Top-Up Vouchers and filter by the Batch Tag of the batch.
  2. Check that the number of vouchers, the Book Value and the status Active are as expected.
  3. Redeem one voucher on a test account and check that its balance grows by the book value.