Add to Wishlist

Adds the product to wishlist

Description

The addToWishlist action adds a product to the logged-in customer’s wishlist. It helps users save products for later, enhancing engagement and retention while allowing personalized shopping experiences.

Function Signature

VajroSDK.actions.addToWishlist({productId: "1234234342", variantId: "2342134234"})
ParameterTypeRequiredDescription
productIdStringYesUnique ID of the product available in Shopify.
variantIdStringYesUnique ID of the variant available in Shopify.

Structure of Response

StatusResponse
Success{ "status": "success", "message": "Added to Wishlist" }
Invalid Product Id{ "status": "error", "errorId": 400, "errorHandle": "invalid-product-Id", "message": "Invalid Product Id" }
User Not Logged In{ "status": "error", "errorId": 400, "errorHandle": "user-not-logged-in", "message": "The user is not logged in" }
Unexpected Error{ "status": "error", "errorId": 500, "errorHandle": "unknown-error", "message": "Something unexpected happened" }

Example Usage

const btnWishlist = document.getElementById("add-to-wishlist");
btnWishlist.addEventListener("click", async () => {
const product = VajroSDK.variables.product;
const variant = product?.selectedVariant;
const customerId = VajroSDK.variables.customer?.id;
  if (!customerId) {
await VajroSDK.actions.openAuthentication({ type: "login" });
    return;  
}
  VajroSDK.actions.addToWishlist({
        productId: product.id,
        variantId: variant.id,
      });

});

<button id="add-to-wishlist">Add to Wishlist</button>

Best Practices

  1. Ensure login: Always check if the customer is authenticated before calling this action.
  2. Show instant feedback: Use showToast or update the UI immediately for a responsive experience.
  3. Sync UI state: Pair with wishlistUpdated listener to automatically refresh icons or counters.
  4. Avoid spamming: Prevent rapid repeated clicks to avoid duplicate entries.
  5. Track engagement: Log wishlist additions to understand product interest.

Caveats

  1. Requires login: Only available to authenticated customers.
  2. App-only: Works inside the Superfans mobile app environment.
  3. Async behavior: Returns a Promise — handle responses gracefully.
  4. Immediate sync: Wishlist updates happen instantly but may take a moment to reflect in UI.
  5. Error handling: Always include .catch() for failed attempts or connectivity issues.