Meet Toki Operator

Docs/Wallet SDK

Tiers

Your tiers and paid memberships, the customer's progress to the next tier, and tier rewards.

A tier is a membership level customers unlock by meeting its conditions, such as a points balance or a number of orders. Paid memberships, which customers buy, come back in the same lists with type: "paid". Your membership order ranks them from entry tier to highest, and each one can have rewards, such as a discount code or free shipping.

getTiers#

tokiWallet.getTiers({ ids? })→ Promise<{ tiers: Tier[] }>

Lists your active tiers and paid memberships with their unlock conditions and rewards.

Works for guests. Tiers come in your membership order. Each customer sees the tiers you show to everyone, plus the ones you show only to some segments or only to their members when they qualify. For a signed-in customer, isOpened marks the tiers they're in.

Options

one object
  • idsstring[]

    Only these tiers.

Returns

Promise<{ tiers: Tier[] }>
  • tiersTier[]
    10 fields per item
    • idstring
    • namestring

      As you entered it.

    • type"tiers" | "paid"

      "tiers" for a tier customers unlock, "paid" for a paid membership.

    • isOpenedboolean

      The signed-in customer is in this tier; false for guests.

    • isStackableboolean

      Whether the tier's rewards add up with a higher tier's. A customer in several tiers that don't stack gets the highest one's rewards.

    • orderNumbernumber | null

      Its place in your membership order.

    • membershipCardstring | null

      Image URL of its membership card.

    • operator"AND" | "OR"

      Whether a customer meets the tier with all of its unlock conditions, or with any one of them.

    • unlockConditionMessagesstring[]

      The unlock conditions in words, in the storefront language, such as "> 1,000 Points", "Spend $500" or "Make 5+ orders".

    • rewardsTierReward[]

      In the order you set.

      5 fields per item
      • idstring
      • typestring

        "discount", "free-shipping", "gift", "custom", "membership_card" (a collectible), "asset" (points), "accelerator" (earn faster), "gating" (gated content), "multiplier-votes", "tremendous" or "shopify-store-credit".

      • messagestring

        The reward in words, in the storefront language, such as "10% Discount", "Free shipping" or "2x for each activity". The reward's name when you gave it one.

      • descriptionstring | null

        Your description; null when there's none.

      • metaRewardMeta

        Details that depend on type.

        14 fields
        • isHiddenbooleanOptional

          true when the reward isn't available to the customer right now, for example a one-time reward they've already used.

        • isRedeemedbooleanOptional

          The customer has redeemed the reward as many times as it allows.

        • redemptionProgress{ count: number; limit: number }Optional

          For rewards with a redemption limit: how many times the customer has redeemed it, out of limit.

        • isUseAutomaticPerksbooleanOptional

          Discounts and free shipping: true when the reward applies automatically at checkout.

        • discountType"percentage" | "fixed"Optional

          Discounts.

        • discountAmountnumberOptional

          Discounts: the percentage, such as 10, or the amount off in your store currency.

        • minimumPurchaseAmountnumber | stringOptional

          Discounts and free shipping: the subtotal the code needs, in your store currency.

        • giftType"manual" | "automated"Optional

          Gifts: customers redeem "manual" gifts in the wallet, and Toki sends "automated" gifts when the customer enters the tier.

        • shopifyProductVariants{ id: string; label: string }[]Optional

          Gifts: the products the customer can choose from. id is the Shopify variant ID.

        • acceleratorRatenumber | stringOptional

          Accelerators: how many times the usual points the customer earns, such as "2".

        • multiplierVotesnumber | stringOptional

          Vote multipliers: how many times the customer's poll votes count.

        • activityIdsstring[]Optional

          Gated content: the activities the reward unlocks.

        • gatedPagesstring[]Optional

          Gated content: the pages the reward unlocks.

        • buttonSettings{ enabled: boolean; buttonText?: string; url?: string }

          A button you set up on the reward: its text and the link it opens.

Example
const { tiers } = await tokiWallet.getTiers()
const current = tiers
  .filter((tier) => tier.isOpened)
  .at(-1)
Result
{
  "tiers": [
    {
      "id": "0f2d8a64-3c1b-4e5f-9a7d-2b6c8e1f4a90",
      "name": "Gold",
      "type": "tiers",
      "isOpened": true,
      "isStackable": true,
      "orderNumber": 2,
      "membershipCard": "https://cdn.buildwithtoki.com/acme-coffee/gold-card.png",
      "operator": "OR",
      "unlockConditionMessages": [
        "> 1,000 Points"
      ],
      "rewards": [
        {
          "id": "c1d2e3f4-a5b6-4c7d-8e9f-0a1b2c3d4e5f",
          "type": "discount",
          "message": "10% Discount",
          "description": null,
          "meta": {
            "discountAmount": 10,
            "discountType": "percentage",
            "buttonSettings": {
              "enabled": false
            }
          }
        }
      ]
    }
  ]
}

getCustomerTiers#

tokiWallet.getCustomerTiers()→ Promise<Tier[]>

Lists the tiers and paid memberships the customer is in, with the rewards they get from each.

Tiers come in your membership order, highest last. When the customer is in several tiers that don't stack, the highest of those carries the rewards and the others have an empty rewards list. Rewards the customer can't use right now are included, with meta.isHidden set.

Returns

Promise<Tier[]>

The same fields as in getTiers().

  • idstring
  • namestring

    As you entered it.

  • type"tiers" | "paid"

    "tiers" for a tier customers unlock, "paid" for a paid membership.

  • isOpenedboolean

    The signed-in customer is in this tier; false for guests.

  • isStackableboolean

    Whether the tier's rewards add up with a higher tier's. A customer in several tiers that don't stack gets the highest one's rewards.

  • orderNumbernumber | null

    Its place in your membership order.

  • membershipCardstring | null

    Image URL of its membership card.

  • operator"AND" | "OR"

    Whether a customer meets the tier with all of its unlock conditions, or with any one of them.

  • unlockConditionMessagesstring[]

    The unlock conditions in words, in the storefront language, such as "> 1,000 Points", "Spend $500" or "Make 5+ orders".

  • rewardsTierReward[]

    In the order you set.

    5 fields per item
    • idstring
    • typestring

      "discount", "free-shipping", "gift", "custom", "membership_card" (a collectible), "asset" (points), "accelerator" (earn faster), "gating" (gated content), "multiplier-votes", "tremendous" or "shopify-store-credit".

    • messagestring

      The reward in words, in the storefront language, such as "10% Discount", "Free shipping" or "2x for each activity". The reward's name when you gave it one.

    • descriptionstring | null

      Your description; null when there's none.

    • metaRewardMeta

      Details that depend on type.

      14 fields
      • isHiddenbooleanOptional

        true when the reward isn't available to the customer right now, for example a one-time reward they've already used.

      • isRedeemedbooleanOptional

        The customer has redeemed the reward as many times as it allows.

      • redemptionProgress{ count: number; limit: number }Optional

        For rewards with a redemption limit: how many times the customer has redeemed it, out of limit.

      • isUseAutomaticPerksbooleanOptional

        Discounts and free shipping: true when the reward applies automatically at checkout.

      • discountType"percentage" | "fixed"Optional

        Discounts.

      • discountAmountnumberOptional

        Discounts: the percentage, such as 10, or the amount off in your store currency.

      • minimumPurchaseAmountnumber | stringOptional

        Discounts and free shipping: the subtotal the code needs, in your store currency.

      • giftType"manual" | "automated"Optional

        Gifts: customers redeem "manual" gifts in the wallet, and Toki sends "automated" gifts when the customer enters the tier.

      • shopifyProductVariants{ id: string; label: string }[]Optional

        Gifts: the products the customer can choose from. id is the Shopify variant ID.

      • acceleratorRatenumber | stringOptional

        Accelerators: how many times the usual points the customer earns, such as "2".

      • multiplierVotesnumber | stringOptional

        Vote multipliers: how many times the customer's poll votes count.

      • activityIdsstring[]Optional

        Gated content: the activities the reward unlocks.

      • gatedPagesstring[]Optional

        Gated content: the pages the reward unlocks.

      • buttonSettings{ enabled: boolean; buttonText?: string; url?: string }

        A button you set up on the reward: its text and the link it opens.

Example
const customerTiers = await tokiWallet.getCustomerTiers()
const highest = customerTiers.at(-1)?.name
Result
[
  {
    "id": "0f2d8a64-3c1b-4e5f-9a7d-2b6c8e1f4a90",
    "name": "Gold",
    "type": "tiers",
    "isOpened": true,
    "isStackable": false,
    "orderNumber": 2,
    "membershipCard": "https://cdn.buildwithtoki.com/acme-coffee/gold-card.png",
    "operator": "OR",
    "unlockConditionMessages": [
      "> 1,000 Points"
    ],
    "rewards": [
      {
        "id": "4b8e1c2d-7f3a-4d9e-b0c5-6a2f8e1d3b97",
        "type": "free-shipping",
        "message": "Free shipping",
        "description": null,
        "meta": {
          "minimumPurchaseAmount": "50",
          "buttonSettings": {
            "enabled": false
          }
        }
      }
    ]
  }
]

getNextTier#

tokiWallet.getNextTier({ tierIds? })→ Promise<NextTier>

Returns the customer's next tier and how far they are from it.

The next tier is the first one in your membership order above the highest tier the customer is in, skipping tiers they can't see and tiers with no places left. Without tierIds, all your tiers and paid memberships count.

message and status are ready to show, in the storefront language. When the customer is in every tier, isMaxLevel is true, progress is 100 and tier is null.

Options

one object
  • tierIdsstring[]

    Only consider these tiers and paid memberships.

Returns

Promise<NextTier>
  • tier{ id: string; name: string; requiredPoints: number } | null

    The next tier; null when there's none. requiredPoints is what its unlock conditions ask for in points, or 0 when they don't involve points.

  • isMaxLevelboolean

    The customer is in every tier they can see.

  • progressnumber

    How far the customer is toward the next tier, as a percentage from 0 to 100.

  • progressFor"points" | "activity" | null

    The kind of condition progress follows: points, or completing an activity. null for other conditions, such as a number of orders.

  • pointsnumber

    The customer's points that count toward the next tier.

  • activity{ name: string; completed: number; required: number } | null

    When progressFor is "activity": the activity, how many times the customer has completed it, and how many times the tier asks for. Otherwise null.

  • messagestring

    Such as "You're 250 Points away from Gold", or "Congratulations! You have already reached max level" in the top tier.

  • statusstring

    Where the customer stands, such as "750 Points", "Made 3 orders" or "Spent $120".

Example
const { message, progress } =
  await tokiWallet.getNextTier()
document.querySelector("#tier-message").textContent =
  message
document.querySelector(
  "#tier-bar",
).style.width = `${progress}%`
Result
{
  "tier": {
    "id": "0f2d8a64-3c1b-4e5f-9a7d-2b6c8e1f4a90",
    "name": "Gold",
    "requiredPoints": 1000
  },
  "isMaxLevel": false,
  "progress": 75,
  "progressFor": "points",
  "points": 750,
  "activity": null,
  "message": "You're 250 Points away from Gold",
  "status": "750 Points"
}

getTierRewards#

tokiWallet.getTierRewards()→ Promise<TierRewardItem[]>

Lists the rewards from the customer's tiers in one list.

The same rewards as in getCustomerTiers(), without the tiers around them. Rewards the customer can't use right now are included, with meta.isHidden set.

Returns

Promise<TierRewardItem[]>
  • tierRewardIdstring
  • rewardMessagestring

    The reward in words, in the storefront language, such as "10% Discount".

  • typestring

    "discount", "free-shipping", "gift", "custom", "membership_card" (a collectible), "asset" (points), "accelerator" (earn faster), "gating" (gated content), "multiplier-votes", "tremendous" or "shopify-store-credit".

  • metaRewardMeta

    Details that depend on type.

    14 fields
    • isHiddenbooleanOptional

      true when the reward isn't available to the customer right now, for example a one-time reward they've already used.

    • isRedeemedbooleanOptional

      The customer has redeemed the reward as many times as it allows.

    • redemptionProgress{ count: number; limit: number }Optional

      For rewards with a redemption limit: how many times the customer has redeemed it, out of limit.

    • isUseAutomaticPerksbooleanOptional

      Discounts and free shipping: true when the reward applies automatically at checkout.

    • discountType"percentage" | "fixed"Optional

      Discounts.

    • discountAmountnumberOptional

      Discounts: the percentage, such as 10, or the amount off in your store currency.

    • minimumPurchaseAmountnumber | stringOptional

      Discounts and free shipping: the subtotal the code needs, in your store currency.

    • giftType"manual" | "automated"Optional

      Gifts: customers redeem "manual" gifts in the wallet, and Toki sends "automated" gifts when the customer enters the tier.

    • shopifyProductVariants{ id: string; label: string }[]Optional

      Gifts: the products the customer can choose from. id is the Shopify variant ID.

    • acceleratorRatenumber | stringOptional

      Accelerators: how many times the usual points the customer earns, such as "2".

    • multiplierVotesnumber | stringOptional

      Vote multipliers: how many times the customer's poll votes count.

    • activityIdsstring[]Optional

      Gated content: the activities the reward unlocks.

    • gatedPagesstring[]Optional

      Gated content: the pages the reward unlocks.

    • buttonSettings{ enabled: boolean; buttonText?: string; url?: string }

      A button you set up on the reward: its text and the link it opens.

Example
const rewards = await tokiWallet.getTierRewards()
const available = rewards.filter(
  (reward) => !reward.meta.isHidden,
)
Result
[
  {
    "tierRewardId": "c1d2e3f4-a5b6-4c7d-8e9f-0a1b2c3d4e5f",
    "rewardMessage": "10% Discount",
    "type": "discount",
    "meta": {
      "discountAmount": 10,
      "discountType": "percentage",
      "buttonSettings": {
        "enabled": false
      }
    }
  }
]