Meet Toki Operator

Docs/Wallet SDK

Wishlist

Customers' wishlists: save products, organize them in named lists, share them and check them out.

A customer can have several named wishlists, such as Favorites, each holding the products they saved. Signed-in customers' wishlists are saved to their account. Pass allowGuests: true to let guests use wishlists too: theirs are kept in this browser and move to their account when they sign in.

getWishlists#

tokiWallet.getWishlists({ allowGuests? })→ Promise<Wishlist[]>

Lists the customer's wishlists with their items.

Signed-in customers get the wishlists saved to their account, and guests the ones saved in this browser when you pass allowGuests: true. Match allowGuests to the Allow Anonymous Wishlists setting of your Wishlist Button design so your code and the button show the same wishlists.

A customer without wishlists gets an empty Favorites wishlist with the ID default_collection, and so does a guest when you leave out allowGuests. addToWishlist creates it, with its own ID, when the customer saves a product to it.

When a guest signs in, Toki moves the wishlists saved in this browser to their account, merging wishlists with the same name, and then dispatches tokiWalletUserAuthenticated. Read the wishlists again on that event: they have new IDs.

Options

one object
  • allowGuestsbooleandefault false

    Let guests use the wishlists saved in this browser. Has no effect for signed-in customers.

Returns

Promise<Wishlist[]>
  • idstring
  • namestring
  • itemsWishlistItem[]
    6 fields per item
    • idstring

      The item's ID, for removeFromWishlist and moveWishlistItem.

    • product_idstring

      Shopify's numeric product ID.

    • variant_idstring
    • labelstring | null

      The product's title.

    • image_urlstring | null

      An image of the product.

    • variantsWishlistItemVariant[]Optional

      Included for signed-in customers: the product's variants, up to 100, for a variant picker or an add-to-cart button.

      4 fields per item
      • idstring

        Shopify's numeric variant ID.

      • titlestring

        The variant's title, such as M / Sand, or Default Title for a product without options.

      • pricestring

        A decimal string in your store's default currency, such as "49.90".

      • availableForSaleboolean
Example
const wishlists = await tokiWallet.getWishlists({
  allowGuests: true,
})
const savedCount = wishlists.reduce(
  (sum, wishlist) => sum + wishlist.items.length,
  0,
)
Result
[
  {
    "id": "0b6f6f4e-2a51-4c1e-9d8e-3f1f5a7c9b21",
    "name": "Favorites",
    "items": [
      {
        "id": "c3a1d2e4-5f60-4b7a-8c9d-0e1f2a3b4c5d",
        "product_id": "8123456789012",
        "variant_id": "44123456789012",
        "label": "Linen Shirt",
        "image_url": "https://cdn.shopify.com/s/files/1/0612/3456/7890/files/linen-shirt.jpg",
        "variants": [
          {
            "id": "44123456789012",
            "title": "M / Sand",
            "price": "49.90",
            "availableForSale": true
          }
        ]
      }
    ]
  }
]

addToWishlist#

tokiWallet.addToWishlist({ productId, … })→ Promise<WishlistItemRef>

Saves a product to one of the customer's wishlists.

Leave out wishlistId to save to the customer's Favorites wishlist, or to the one named wishlistName; Toki creates it if the customer doesn't have it yet. Passing default_collection as wishlistId does the same. Pass variantId to save a specific variant. Saving a product and variant that are already in the wishlist resolves to the existing item.

For signed-in customers, a new item fires Wishlist Item Added in your workflows and connected email and SMS tools; a guest's items fire it when they sign in. For guests, pass allowGuests: true.

Options

one object
  • productIdstringRequired

    Shopify's numeric product ID, as a string, such as "8123456789012".

  • variantIdstring

    Shopify's numeric variant ID, as a string.

  • wishlistIdstringdefault "default_collection"

    The wishlist to save to, from getWishlists.

  • wishlistNamestringdefault "Favorites"

    The name of the wishlist to save to when you leave out wishlistId.

  • allowGuestsbooleandefault false

    Let guests use the wishlists saved in this browser. Has no effect for signed-in customers.

Returns

Promise<WishlistItemRef>

The saved item.

  • idstring

    The item's ID, for removeFromWishlist and moveWishlistItem.

  • wishlist_idstring

    The ID of the wishlist the item is in.

  • product_idstring

    Shopify's numeric product ID.

  • variant_idstring
Example
const item = await tokiWallet.addToWishlist({
  productId: "8123456789012",
  variantId: "44123456789012",
  allowGuests: true,
})
Result
{
  "id": "c3a1d2e4-5f60-4b7a-8c9d-0e1f2a3b4c5d",
  "wishlist_id": "0b6f6f4e-2a51-4c1e-9d8e-3f1f5a7c9b21",
  "product_id": "8123456789012",
  "variant_id": "44123456789012"
}

isInWishlist#

tokiWallet.isInWishlist({ productId, variantId?, allowGuests? })→ Promise<boolean>

Returns whether a product is in any of the customer's wishlists.

With variantId, only that variant counts; without it, any variant of the product does. Calls made within 50 ms of each other are sent together in one request, so you can call it for every product card on a page.

For guests, it checks the wishlists saved in this browser when you pass allowGuests: true, and resolves false otherwise. To remove the product, use findWishlistItem, which gives you the item.

Options

one object
  • productIdstringRequired

    Shopify's numeric product ID, as a string, such as "8123456789012".

  • variantIdstring

    Shopify's numeric variant ID, as a string.

  • allowGuestsbooleandefault false

    Let guests use the wishlists saved in this browser. Has no effect for signed-in customers.

Returns

Promise<boolean>
Example
const saved = await tokiWallet.isInWishlist({
  productId: "8123456789012",
  allowGuests: true,
})
heartButton.setAttribute("aria-pressed", String(saved))
Result
true

findWishlistItem#

tokiWallet.findWishlistItem({ productId, variantId?, allowGuests? })→ Promise<WishlistItemRef | null>

Returns the customer's wishlist item for a product, or null when it isn't saved.

Takes the same options as isInWishlist and shares its batching. Use it when you need the item, for example to remove the product when the customer clicks a filled heart. When the product is in several wishlists, you get one of its items.

For guests, it checks the wishlists saved in this browser when you pass allowGuests: true, and resolves null otherwise.

Options

one object
  • productIdstringRequired

    Shopify's numeric product ID, as a string, such as "8123456789012".

  • variantIdstring

    Shopify's numeric variant ID, as a string.

  • allowGuestsbooleandefault false

    Let guests use the wishlists saved in this browser. Has no effect for signed-in customers.

Returns

Promise<WishlistItemRef | null>
  • idstring

    The item's ID, for removeFromWishlist and moveWishlistItem.

  • wishlist_idstring

    The ID of the wishlist the item is in.

  • product_idstring

    Shopify's numeric product ID.

  • variant_idstring
Example
const item = await tokiWallet.findWishlistItem({
  productId: "8123456789012",
  allowGuests: true,
})
Result
{
  "id": "c3a1d2e4-5f60-4b7a-8c9d-0e1f2a3b4c5d",
  "wishlist_id": "0b6f6f4e-2a51-4c1e-9d8e-3f1f5a7c9b21",
  "product_id": "8123456789012",
  "variant_id": "44123456789012"
}

removeFromWishlist#

tokiWallet.removeFromWishlist({ itemId, allowGuests? })→ Promise<void>

Removes an item from the customer's wishlist.

Only that item is removed: the same product stays in the customer's other wishlists. For signed-in customers, it fires Wishlist Item Removed in your workflows and connected email and SMS tools. For guests, pass allowGuests: true.

Options

one object
  • itemIdstringRequired

    The item's id, from getWishlists, findWishlistItem or addToWishlist.

  • allowGuestsbooleandefault false

    Let guests use the wishlists saved in this browser. Has no effect for signed-in customers.

Returns

Promise<void>

Nothing, once it's done.

Example
await tokiWallet.removeFromWishlist({
  itemId: "c3a1d2e4-5f60-4b7a-8c9d-0e1f2a3b4c5d",
  allowGuests: true,
})
read

getProductWishlistCount#

tokiWallet.getProductWishlistCount({ productId, variantId? })→ Promise<number>

Returns how many times a product is saved in wishlists across your store.

Every save counts, so a customer who has the product in two wishlists counts twice. Without variantId, all variants count. For guests, the products saved in this browser are included. Use it for a counter like the one on Toki's Wishlist Button. Calls made within 50 ms of each other are sent together in one request.

Options

one object
  • productIdstringRequired

    Shopify's numeric product ID, as a string, such as "8123456789012".

  • variantIdstring

    Shopify's numeric variant ID, as a string.

Returns

Promise<number>
Example
const count = await tokiWallet.getProductWishlistCount({
  productId: "8123456789012",
})
counter.textContent = count > 0 ? String(count) : ""
Result
37

createWishlist#

tokiWallet.createWishlist({ name, allowGuests? })→ Promise<Wishlist>

Creates an empty wishlist for the customer.

Names don't have to be unique. For signed-in customers, it fires Wishlist Collections Changed in your workflows and connected email and SMS tools. For guests, pass allowGuests: true.

Options

one object
  • namestringRequired

    The wishlist's name, such as "Birthday ideas".

  • allowGuestsbooleandefault false

    Let guests use the wishlists saved in this browser. Has no effect for signed-in customers.

Returns

Promise<Wishlist>

The new wishlist.

  • idstring
  • namestring
  • itemsWishlistItem[]

    Empty for a new wishlist.

Example
const wishlist = await tokiWallet.createWishlist({
  name: "Birthday ideas",
  allowGuests: true,
})
Result
{
  "id": "7d2e9c1a-4b3f-4e8d-9a6c-5f1e2d3c4b5a",
  "name": "Birthday ideas",
  "items": []
}

renameWishlist#

tokiWallet.renameWishlist({ wishlistId, name, allowGuests? })→ Promise<void>

Renames one of the customer's wishlists.

Rejects when the wishlist doesn't exist or isn't the customer's. For signed-in customers, it fires Wishlist Collections Changed in your workflows and connected email and SMS tools. For guests, pass allowGuests: true.

Options

one object
  • wishlistIdstringRequired

    The wishlist to rename.

  • namestringRequired

    The new name.

  • allowGuestsbooleandefault false

    Let guests use the wishlists saved in this browser. Has no effect for signed-in customers.

Returns

Promise<void>

Nothing, once it's done.

Example
await tokiWallet.renameWishlist({
  wishlistId: "7d2e9c1a-4b3f-4e8d-9a6c-5f1e2d3c4b5a",
  name: "Gift ideas",
})

deleteWishlist#

tokiWallet.deleteWishlist({ wishlistId, allowGuests? })→ Promise<void>

Deletes one of the customer's wishlists with every item in it.

For signed-in customers, it fires Wishlist Collections Changed in your workflows and connected email and SMS tools. For guests, pass allowGuests: true.

Options

one object
  • wishlistIdstringRequired

    The wishlist to delete.

  • allowGuestsbooleandefault false

    Let guests use the wishlists saved in this browser. Has no effect for signed-in customers.

Returns

Promise<void>

Nothing, once it's done.

Example
await tokiWallet.deleteWishlist({
  wishlistId: "7d2e9c1a-4b3f-4e8d-9a6c-5f1e2d3c4b5a",
})

moveWishlistItem#

tokiWallet.moveWishlistItem({ itemId, wishlistId, allowGuests? })→ Promise<void>

Moves an item to another of the customer's wishlists.

Rejects when the item or the target wishlist isn't the customer's. For signed-in customers, it fires Wishlist Collections Changed for the target wishlist in your workflows and connected email and SMS tools. For guests, pass allowGuests: true.

Options

one object
  • itemIdstringRequired

    The item's id.

  • wishlistIdstringRequired

    The wishlist to move the item to.

  • allowGuestsbooleandefault false

    Let guests use the wishlists saved in this browser. Has no effect for signed-in customers.

Returns

Promise<void>

Nothing, once it's done.

Example
await tokiWallet.moveWishlistItem({
  itemId: "c3a1d2e4-5f60-4b7a-8c9d-0e1f2a3b4c5d",
  wishlistId: "7d2e9c1a-4b3f-4e8d-9a6c-5f1e2d3c4b5a",
})
read

getSharedWishlists#

tokiWallet.getSharedWishlists({ wishlistIds })→ Promise<SharedWishlist[]>

Returns wishlists that someone shared, by their IDs.

Toki's Wishlist Block shares wishlists as a link to the current page with a tkwishlist parameter holding the wishlist IDs, separated by commas, and shows those wishlists when someone opens the link. Use the same parameter to make your share links work with the block.

It works for everyone, signed in or not. Wishlists saved to a customer's account can be shared; to let the customer keep one, copy it with copyWishlist.

Options

one object
  • wishlistIdsstring[]Required

    The wishlists' IDs, such as the ones from a share link.

Returns

Promise<SharedWishlist[]>
  • idstring
  • namestring
  • owner_namestring

    The full name of the wishlist's owner, or an empty string.

  • itemsSharedWishlistItem[]
    6 fields per item
    • idstring
    • product_idstring

      Shopify's numeric product ID.

    • variant_idstring
    • labelstring | null

      The saved variant's name, such as Linen Shirt (M / Sand).

    • pricenumber | null

      The saved variant's price in your store's default currency, such as 49.9.

    • image_urlstring | null

      An image of the product.

Example
const param = new URL(location.href).searchParams.get(
  "tkwishlist",
)
const shared = param
  ? await tokiWallet.getSharedWishlists({
      wishlistIds: param.split(","),
    })
  : []
Result
[
  {
    "id": "0b6f6f4e-2a51-4c1e-9d8e-3f1f5a7c9b21",
    "name": "Birthday ideas",
    "owner_name": "Anna Smith",
    "items": [
      {
        "id": "c3a1d2e4-5f60-4b7a-8c9d-0e1f2a3b4c5d",
        "product_id": "8123456789012",
        "variant_id": "44123456789012",
        "label": "Linen Shirt (M / Sand)",
        "price": 49.9,
        "image_url": "https://cdn.shopify.com/s/files/1/0612/3456/7890/files/linen-shirt.jpg"
      }
    ]
  }
]

copyWishlist#

tokiWallet.copyWishlist({ wishlistId })→ Promise<void>

Copies a wishlist, with its items, into the customer's wishlists.

Use it to let the customer keep a wishlist someone shared with them. The copy has the same name; call getWishlists to see it. Rejects when the wishlist doesn't exist. It fires Wishlist Collections Changed in your workflows and connected email and SMS tools.

Options

one object
  • wishlistIdstringRequired

    The wishlist to copy, such as one from getSharedWishlists.

Returns

Promise<void>

Nothing, once it's done.

Example
await tokiWallet.copyWishlist({
  wishlistId: "0b6f6f4e-2a51-4c1e-9d8e-3f1f5a7c9b21",
})

createWishlistCheckout#

tokiWallet.createWishlistCheckout({ wishlistIds })→ Promise<WishlistCheckout>

Creates a checkout with the items of the customer's wishlists and returns its URL.

Toki creates a new Shopify cart with each item's saved variant, quantity 1, and resolves to its checkout URL, with the customer's email filled in. It takes up to 100 items and adds the ones that are available for sale. The customer's current cart stays as it is, and nothing navigates: send the customer to checkoutUrl yourself.

It uses the customer's own wishlists; to check out a shared one, copy it with copyWishlist first.

Options

one object
  • wishlistIdsstring[]Required

    The customer's wishlists to check out, at least one.

Returns

Promise<WishlistCheckout>
  • checkoutUrlstring

    The checkout URL of the new cart.

Example
const { checkoutUrl } =
  await tokiWallet.createWishlistCheckout({
    wishlistIds: ["0b6f6f4e-2a51-4c1e-9d8e-3f1f5a7c9b21"],
  })
window.location.href = checkoutUrl
Result
{
  "checkoutUrl": "https://your-store.com/cart/c/hWN1e2Lx7QpZbVt3RkY9sDmA?key=6c1f0b2d9e8a7f4c"
}
read

getProductVisitUrl#

tokiWallet.getProductVisitUrl({ productId, variantId? })→ Promise<string>

Returns a link to a product's page in your store.

Use it to link wishlist items to their product pages, as Toki's wishlist blocks do. The link goes through Toki, which finds the product's page and redirects there, with the variant selected when you pass variantId. It returns the link right away, not a promise, and works for everyone.

Options

one object
  • productIdstringRequired

    Shopify's numeric product ID.

  • variantIdstring

    Shopify's numeric variant ID.

Returns

Promise<string>
Example
link.href = tokiWallet.getProductVisitUrl({
  productId: item.product_id,
  variantId: item.variant_id,
})