Meet Toki Operator

Docs/Wallet SDK

Ways to earn

Your activities and their rewards, referral links and redeem codes.

An activity is a way to earn, such as placing an order, following you on Instagram or celebrating a birthday. Each activity has a reward, which can differ by customer segment. A referral has two sides: the customer who shares their link, the referrer, earns a reward, and the friend they bring gets a discount.

getActivities#

tokiWallet.getActivities({ ids?, types?, excludeTypes? })→ Promise<Activity[]>

Lists your active ways to earn, with each one's reward and the customer's progress.

Works for guests, who see the activities with a reward for everyone. For a signed-in customer, the reward for their segment sets rewardMessage, and completed, limitReached and pendingReview show their progress. Without ids, the most recently updated activity comes first.

Options

one object
  • idsstring[]

    Only these activities, in this order.

  • typesstring[]

    Only activities of these types, such as ["BIRTHDAY", "REFER_A_FRIEND"]; see typeIdentifier.

  • excludeTypesstring[]

    Leave out activities of these types.

Returns

Promise<Activity[]>
  • idstring
  • typeIdentifierstring

    The kind of activity. Purchases: SHOPIFY_PURCHASE, SHOPIFY_BASED_ON_SPEND (a spending goal). Referrals: REFER_A_FRIEND, SHARE_WITH_FRIENDS (refer a friend to the brand), REFER_A_FRIEND_TO_COMPLETE_AN_ACTIVITY. Engagement: JOIN_REWARDS_PROGRAM, COLLECT_ZERO_PARTY_DATA (surveys), QUIZ, VOTING (polls), PICTURE_SUBMISSION, BIRTHDAY, LOYALTY_ANNIVERSARY, LINK_CLICKS. Social: INSTAGRAM_FOLLOW, INSTAGRAM_LIKE_POST, INSTAGRAM_COMMENT_POST, INSTAGRAM_POST_UGC, TIKTOK_FOLLOW, TIKTOK_LIKE_POST, TIKTOK_VIDEO_CREATION, FACEBOOK_LIKE_PAGE, FACEBOOK_LIKE_POST, FACEBOOK_COMMENT_POST, FACEBOOK_JOIN_GROUP, TWITTER_FOLLOW, TWITTER_LIKE_POST, TWITTER_COMMENT_POST, TWITTER_RETWEET, DISCORD_JOIN_CHANNEL, YOUTUBE_SUBSCRIBE, PINTEREST_FOLLOW, SHARE_PURCHASE_ON_SOCIAL. Subscriptions: SUBSCRIPTION_SIGN_UP, SUBSCRIPTION_CONTINUATION. Other: CHALLENGE, NON_INTEGRATION_CUSTOM, DOWNLOAD_PASS, NEWSLETTER_SIGN_UP, SIGN_IN_REWARDS, SCAN_QR_CODE, SPIN_WHEEL, LOTTERY, CHARITY, REDEEM_CODE. Integrations: KLAVIYO_SIGNUP, POSTSCRIPT_SMS_SIGN_UP, TAGGUN_SEND_RECEIPT, GREENSPARK_IMPACT. Reviews and surveys: REVIEWS, JUDGE_ME_CREATE_REVIEW, ACTION_LOOX_REVIEWS, ACTION_OKENDO, ACTION_REVIEWS_IO, ACTION_STAMPED, ACTION_YOTPO, ACTION_FAIRING.

  • namestring

    As you entered it.

  • descriptionstring

    As you entered it; empty when there's none.

  • rewardMessagestring

    The customer's reward in words, in the storefront language, such as "100 Points", "$5 Discount" or "5% back in Points".

  • urlstring

    The activity's link, such as your Instagram profile; empty when it has none.

  • imagestring | null

    Image URL.

  • iconImagestring | null

    Icon URL.

  • completedboolean

    true once the customer has done a one-time activity or reached completionsLimit.

  • limitReachedboolean

    The customer has reached completionsLimit for the current period.

  • pendingReviewboolean

    One of the customer's completions is waiting for your approval.

  • completionsLimitobject

    How often a customer can complete the activity: { type: "unlimited" }, { type: "fixed", amount } in total, { type: "per-day" }, "per-week" or "per-month" with an amount, or { type: "custom", amount, interval, period }.

  • additionalFieldsobject

    Settings that depend on the type. For SHOPIFY_BASED_ON_SPEND and a signed-in customer, spendProgress holds currentSpend, targetSpend and remainder, in your store currency.

Example
const activities = await tokiWallet.getActivities({
  excludeTypes: ["SHOPIFY_PURCHASE"],
})
Result
[
  {
    "id": "3c9a7e10-5b2f-4d8e-a1c6-0f4b2d9e7a31",
    "typeIdentifier": "INSTAGRAM_FOLLOW",
    "name": "Follow us on Instagram",
    "description": "Follow @acmecoffee for brewing tips.",
    "rewardMessage": "100 Points",
    "url": "https://www.instagram.com/acmecoffee",
    "image": null,
    "iconImage": "https://cdn.buildwithtoki.com/acme-coffee/instagram.png",
    "completed": false,
    "limitReached": false,
    "pendingReview": false,
    "completionsLimit": {
      "type": "fixed",
      "amount": 1
    }
  }
]

getReferralData#

tokiWallet.getReferralData({ activityId?, email? })→ Promise<ReferralData>

Returns a customer's referral code and link, and what the referrer and the friend get.

Each customer has a referral code for each of your referral activities, and the link opens your store with it, so the friend gets their discount. It returns the signed-in customer's code. Pass email to get the code of the member with that email instead, such as a guest who typed theirs in; Toki creates a member for a new email.

Rejects when activityId isn't one of your active referral activities.

Options

one object
  • activityIdstring

    A refer-a-friend activity, or one of type REFER_A_FRIEND_TO_COMPLETE_AN_ACTIVITY. Defaults to your most recently updated refer-a-friend activity.

  • emailstring

    The email of the member whose code you want.

Returns

Promise<ReferralData>
  • codestring

    The referral code.

  • linkstring

    The referral link: your store, or the custom link you set, with the code in tkr, such as https://acme-coffee.com/?tkr=ANNA10&utm_source=toki&utm_medium=referral&utm_campaign=ANNA10.

  • discountCodestring | null

    With Referral code as discount code on, the code the friend can type at checkout; otherwise null.

  • activityReferralActivity
    7 fields
    • idstring
    • amountToRewardstring | null

      The referrer's reward, such as "500": points when tokenToReward is set, otherwise an amount in your store currency.

    • amountToRewardPercentagenumber | null

      For a reward based on spend: the points the referrer earns per unit of currency the friend spends.

    • discountPercentnumber | null

      The friend's discount in percent, such as 15.

    • discountAbsolutestring | null

      The friend's discount as an amount in your store currency, such as "10".

    • tokenToReward{ id: string; name: string; image_url: string }Optional

      The store credit the referrer earns, when their reward is points.

    • additionalFieldsobject

      The activity's settings. minimumOrderAmount is the order total, in your store currency, a friend's order needs to count.

Example
const { link, activity } =
  await tokiWallet.getReferralData()
Result
{
  "code": "ANNA10",
  "link": "https://acme-coffee.com/?tkr=ANNA10&utm_source=toki&utm_medium=referral&utm_campaign=ANNA10",
  "discountCode": null,
  "activity": {
    "id": "7e2c4a90-1d3b-4f5e-8a6c-9b0d2e4f6a18",
    "amountToReward": "500",
    "amountToRewardPercentage": null,
    "discountPercent": 15,
    "discountAbsolute": null,
    "tokenToReward": {
      "id": "6b1f3c52-8a0e-4c1d-9f2a-3e7d5b9c1a04",
      "name": "Points",
      "image_url": ""
    },
    "additionalFields": {
      "minimumOrderAmount": 30
    }
  }
}

redeemCode#

tokiWallet.redeemCode({ code, email? })→ Promise<{ rewardMessage: string }>

Redeems a code from one of your Redeem code activities and gives the customer its reward.

Completes the code's activity for the customer, so they get its reward. Each code can be used as many times as the activity's usage limits allow. Read the balance again afterwards to show the new points.

When the activity has Allow redemption without login on, a guest can redeem with the email they type in, and Toki creates a member for a new email. Otherwise the customer needs to be signed in.

Rejects with a message for the customer, such as "Invalid code", "Code has expired" or "You have already used this code".

Options

one object
  • codestringRequired

    The code. Letter case and surrounding spaces don't matter.

  • emailstring

    For guests: the email of the member to credit.

Returns

Promise<{ rewardMessage: string }>
  • rewardMessagestring

    The reward in words, in the storefront language, such as "500 Points".

Example
const { rewardMessage } = await tokiWallet.redeemCode({
  code: "BEANS-2026",
})
Result
{
  "rewardMessage": "500 Points"
}