Meet Toki Operator

Docs/Wallet SDK

Points & rewards

Balances, pending points, redemption options, discount codes and the total code.

A store credit is your program's currency, usually called Points. Balances and prices are in points, and a store credit's conversion rate says how many points equal one unit of your store currency. Customers spend points on your redemption options, each with a set price and reward, or turn an amount of their choice into a discount code.

getProgram#

tokiWallet.getProgram()→ Promise<Program>

Returns your program's name, default store credit, branding and tiers.

Works for guests. For a signed-in customer, storeCredit.conversionRate is the rate for their segment, and tiers marks the tiers they're in. storeCredit is your default store credit, the first one you created.

Returns

Promise<Program>
  • namestring

    Your store's name.

  • storeCreditStoreCredit
    5 fields
    • idstring
    • namestring

      Such as "Points", in the storefront language.

    • conversionRatenumber

      How many points equal one unit of your store currency for this customer.

    • currency{ code: string; symbol: string }

      The currency for amounts of money, such as { code: "USD", symbol: "$" }.

    • rewardDisplayPreference"store_credit" | "usd" | "both"

      How your program shows amounts: in points ("store_credit"), in your store currency ("usd", whatever the currency is), or both, such as "200 Points ($2)".

  • brandBrand | null

    Your branding from the Toki app; null until you set it.

    3 fields
    • namestring | null

      Your brand name.

    • logoUrlstring | null

      Your logo's URL.

    • coverImageUrlstring | null

      Your cover image's URL.

  • tiersTier[]

    Your tiers and paid memberships, as getTiers() returns them.

Example
const { storeCredit } = await tokiWallet.getProgram()
const rate = `${storeCredit.conversionRate} ${storeCredit.name} = ${storeCredit.currency.symbol}1`
Result
{
  "name": "Acme Coffee",
  "storeCredit": {
    "id": "6b1f3c52-8a0e-4c1d-9f2a-3e7d5b9c1a04",
    "name": "Points",
    "conversionRate": 100,
    "currency": {
      "code": "USD",
      "symbol": "$"
    },
    "rewardDisplayPreference": "both"
  },
  "brand": {
    "name": "Acme Coffee",
    "logoUrl": "https://cdn.buildwithtoki.com/acme-coffee/logo.png",
    "coverImageUrl": null
  },
  "tiers": [
    {
      "id": "0f2d8a64-3c1b-4e5f-9a7d-2b6c8e1f4a90",
      "name": "Gold",
      "type": "tiers",
      "isOpened": true,
      "isStackable": true,
      "orderNumber": 2,
      "membershipCard": null,
      "operator": "OR",
      "unlockConditionMessages": [
        "> 1,000 Points"
      ],
      "rewards": []
    }
  ]
}

getBalance#

tokiWallet.getBalance({ storeCreditId? })→ Promise<Balance>

Returns the customer's balance in a store credit, ready to display.

balance is in points. Divide it by conversionRate for its value in your store currency, or show displayValue, written the way your program shows amounts. Read the balance again on tokiWalletBalanceChanged.

When some of the customer's points have an expiration date, expirationDate and expirationAmount tell you when the next ones expire and how many.

Options

one object
  • storeCreditIdstring

    One of your store credits. Defaults to your default store credit.

Returns

Promise<Balance>
  • balancenumber

    In points.

  • displayValuestring

    The balance as your program shows it: "1,250 Points", "$12.50" or "1,250 Points ($12.50)", with non-breaking spaces.

  • namestring

    The store credit's name.

  • storeCreditIdstring
  • conversionRatenumber

    How many points equal one unit of your store currency for this customer.

  • rewardDisplayPreference"store_credit" | "usd" | "both"

    How your program shows amounts: in points ("store_credit"), in your store currency ("usd", whatever the currency is), or both, such as "200 Points ($2)".

  • expirationDatestringOptional

    When the next points expire, formatted for display, such as "Mar 3, 2027".

  • expirationAmountnumber | nullOptional

    How many points expire on expirationDate; null when it's the whole balance.

Example
const { displayValue } = await tokiWallet.getBalance()
document.querySelector("#points").textContent =
  displayValue
Result
{
  "balance": 1250,
  "displayValue": "1,250 Points ($12.50)",
  "name": "Points",
  "storeCreditId": "6b1f3c52-8a0e-4c1d-9f2a-3e7d5b9c1a04",
  "conversionRate": 100,
  "rewardDisplayPreference": "both",
  "expirationDate": "Mar 3, 2027",
  "expirationAmount": 400
}

getPendingPoints#

tokiWallet.getPendingPoints({ activityIds?, aggregated? })→ Promise<PendingPoints[]>

Lists points the customer has earned that Toki adds later, such as a purchase reward with a reward delay.

Each item says when Toki adds its points. Items with status "CANCELED" won't be added, for example because the order was canceled.

With aggregated: true, it resolves to one total per store credit instead, adding up the pending items. Totals have no date, description, activityName or orderId. When nothing is pending, it resolves to a single total with amount 0.

Options

one object
  • activityIdsstring[]

    Only points from these activities.

  • aggregatedbooleandefault false

    Add the pending points up per store credit.

Returns

Promise<PendingPoints[]>
  • amountnumber

    In points.

  • formattedValuestring

    amount as your program shows it, like displayValue in getBalance().

  • status"PENDING" | "CANCELED"
  • datestring

    When Toki adds the points, as an ISO 8601 date-time.

  • descriptionstring

    The reward's name, or "Activity reward".

  • activityIdstring
  • activityNamestring
  • orderIdstringOptional

    The order that earned the points, when they come from an order.

  • storeCreditStoreCredit

    The store credit the points are in.

    5 fields
    • idstring
    • namestring
    • conversionRatenumber

      How many points equal one unit of your store currency for this customer.

    • currency{ code: string; symbol: string }

      The currency for amounts of money, such as { code: "USD", symbol: "$" }.

    • rewardDisplayPreference"store_credit" | "usd" | "both"

      How your program shows amounts: in points ("store_credit"), in your store currency ("usd", whatever the currency is), or both, such as "200 Points ($2)".

Example
const pending = await tokiWallet.getPendingPoints()
Result
[
  {
    "amount": 240,
    "formattedValue": "240 Points",
    "status": "PENDING",
    "date": "2026-11-12T09:30:00.000Z",
    "description": "Activity reward",
    "activityId": "9d4e2b71-6a3f-4c8d-b5e0-1f7a3c9d2e68",
    "activityName": "Place an order",
    "orderId": "5873412309",
    "storeCredit": {
      "id": "6b1f3c52-8a0e-4c1d-9f2a-3e7d5b9c1a04",
      "name": "Points",
      "conversionRate": 100,
      "currency": {
        "code": "USD",
        "symbol": "$"
      },
      "rewardDisplayPreference": "store_credit"
    }
  }
]

getRedemptionOptions#

tokiWallet.getRedemptionOptions()→ Promise<RedemptionOption[]>

Lists the redemption options available to the customer, in the order you set.

Works for guests. Each customer sees the options available to them right now: those for everyone or for their segments, within their schedule and redemption limits, and offered in their market. Compare amountToSpend with the customer's balance to see which ones they can afford.

Returns

Promise<RedemptionOption[]>
  • idstring

    Pass it to redeemByRule() as ruleId.

  • type"discount" | "free-shipping" | "free-gift" | "collectible" | "custom" | "tremendous" | "shopify-store-credit"

    What the customer gets.

  • amountToSpendnumber

    The price, in points of your default store credit.

  • rewardMessagestring

    The reward in words, in the storefront language, such as "$5 Discount", "Free shipping" or "Gift: Tote bag". The reward's name when you gave it one.

  • descriptionstring

    Your description of the reward; empty when there's none.

  • productVariantIdsstring[]Optional

    Free gifts: the Shopify variant IDs of the products the customer can choose from.

  • settingsobjectOptional

    The reward's settings, which depend on type. For a discount, settings.type is "absolute", "percentage", "buy-x-get-y" or "dynamic", settings.amount is its value as a string, such as "5", and settings.minimumPurchaseAmount is the subtotal the code needs, in your store currency, or null.

Example
const { balance } = await tokiWallet.getBalance()
const options = await tokiWallet.getRedemptionOptions()
const affordable = options.filter(
  (option) => option.amountToSpend <= balance,
)
Result
[
  {
    "id": "a3e1c9f0-2b7d-4f6a-8c15-9e0d4b2a7f63",
    "type": "discount",
    "amountToSpend": 500,
    "rewardMessage": "$5 Discount",
    "description": "",
    "settings": {
      "type": "absolute",
      "amount": "5",
      "minimumPurchaseAmount": null
    }
  }
]

redeemByRule#

tokiWallet.redeemByRule({ ruleId, productVariantId? })→ Promise<RedemptionResult>

Spends the customer's points on a redemption option and returns the reward, usually a discount code.

Deducts the option's amountToSpend from the customer's balance in your default store credit and issues the reward. Discounts, free shipping and free gifts come with a single-use code. For a free gift, openUrl is a checkout link with the gift and its code applied; when the gift has several variants, pass the one the customer chose as productVariantId. For a custom reward, code is your message after redemption, for Shopify Store Credit a message with the amount added, and for a Tremendous gift card a message that it's on its way by email. A collectible goes to the customer's collectibles.

Rejects when the customer doesn't have enough points or the option isn't available to them.

Options

one object
  • ruleIdstringRequired

    The id of an option from getRedemptionOptions().

  • productVariantIdstring

    Free gifts with several variants: the Shopify variant ID the customer chose, one of the option's productVariantIds.

Returns

Promise<RedemptionResult>
  • codestring | null

    The code, or the message to show for custom, Shopify Store Credit and Tremendous rewards; null for collectibles.

  • openUrlstring | null

    Free gifts: a checkout link with the gift in the cart and its code applied.

Events

Example
const [option] = await tokiWallet.getRedemptionOptions()
const { code } = await tokiWallet.redeemByRule({
  ruleId: option.id,
})
await tokiWallet.applyDiscountToShopifyCart(code)
Result
{
  "code": "TISq3V9xK2m",
  "openUrl": null
}

redeemPoints#

tokiWallet.redeemPoints({ amount, storeCreditId? })→ Promise<{ code: string }>

Turns an amount of the customer's points into a single-use discount code worth their value in your store currency.

Deducts amount points and creates a fixed-amount discount code that works once, in any of your stores. The redemption rule that applies to the customer sets its limits: the smallest and largest code they can create, the cart subtotal it needs, and the collections it discounts. You set these per redemption rule on the Loyalty page.

Rejects when the code's value is outside those limits, the cart doesn't reach the minimum spend, or the customer doesn't have enough points.

Options

one object
  • amountnumberRequired

    The points to spend. The code is worth amount divided by the customer's conversion rate: $5 for 500 points at 100 points per dollar.

  • storeCreditIdstring

    The store credit to spend. Defaults to your default store credit.

Returns

Promise<{ code: string }>
  • codestring

    The discount code.

Events

Example
const { code } = await tokiWallet.redeemPoints({
  amount: 500,
})
await tokiWallet.applyDiscountToShopifyCart(code)
Result
{
  "code": "TIS8sKq2LxA"
}

getTotalCode#

tokiWallet.getTotalCode({ storeCreditId? })→ Promise<TotalCode>

Returns the customer's total code: a personal discount code or gift card that spends their balance at checkout.

Toki creates the code the first time you ask for it and returns the same one until it's used. It's worth the customer's balance in your store currency, up to the maximum you set, and follows it as it changes; Toki deducts the points when an order uses it. A new code starts working at checkout shortly after it's created.

A discount code is good for one order; after that, the next call returns a new one. A gift card keeps its code. If the customer's balance drops below the minimum, the code is removed.

available is false when no redemption rule applies to the customer and their cart ("no-redemption-rule"), or when their balance is empty or below the rule's minimum ("not-enough-balance").

Options

one object
  • storeCreditIdstring

    The store credit whose total code you want, when your redemption rules give total codes in more than one.

Returns

Promise<TotalCode>
  • availableboolean

    Whether the customer has a code.

  • codestringOptional

    What the customer enters at checkout, when available is true.

  • type"discount_code" | "gift_card"Optional

    Whether the code is a Shopify discount code or gift card.

  • reason"no-redemption-rule" | "not-enough-balance"Optional

    Why there's no code, when available is false.

  • minimumBalancenumberOptional

    With "not-enough-balance": the balance, in your store currency, the customer needs for a code.

Example
const totalCode = await tokiWallet.getTotalCode()
if (totalCode.available) showCode(totalCode.code)
Result
{
  "available": true,
  "code": "k7m2xq9rtd4wnp3a",
  "type": "discount_code"
}

getUnusedDiscounts#

tokiWallet.getUnusedDiscounts()→ Promise<{ discounts: UnusedDiscount[] }>

Lists the customer's unused discount codes in this store, newest first.

Includes the codes the customer got from spending points, referrals, activities such as a birthday reward, and automations.

Returns

Promise<{ discounts: UnusedDiscount[] }>
  • discountsUnusedDiscount[]
    3 fields per item
    • idstring
    • codestring
    • titlestring

      A short label, such as "$5.00 Off", "15% Off" or "Free Shipping".

Example
const { discounts } =
  await tokiWallet.getUnusedDiscounts()
Result
{
  "discounts": [
    {
      "id": "e5b7c3a1-9f2d-4e8b-a6c0-3d1f7b9e5a24",
      "code": "TISq3V9xK2m",
      "title": "$5.00 Off"
    }
  ]
}