Subscribe for a product alert based on Topic

Subscribe to Back In Stock Product Alert for a product on default storefronts

swat.subscribeForProductAlert

Sign up for a product alert regarding a specific topic. When the conditions relevant to this topic are met, subscribers who have registered via this API will receive an alert email.

Definition

swat.subscribeForProductAlert(mediumValue, medium, product, onSuccess, OnError, addToMailingList, topic)

📘

You may need to integrate this API with your custom form that collects the required details

This API is designed to be wired to your custom forms.

Example

In the following example, alerts are categorised based on topic (either 'backinstock' or 'comingsoon'). When conditions for these topics are met, subscribers registered via this API will receive an alert email.

// Define the email address you want to subscribe to
let mediumValue = "[email protected]"; // Email Address to subscribe
let medium = "email"; // Medium
let topic = "backinstock" // the topic of "backinstock" configured at our backend.

// Product data of the product
let product = {
 	epi: 41254709264582, // unique variant ID of the product.
 	empi: 7096252727494, // Product ID or master product ID
 	du: "https://demo.swym.it/products/1-light-pendant", // canonical product url.
 	iu: "//a.com/b.jpeg", // image url for email
 	pr: 230, // price
 }

// Success Callback
 let onSuccess = function(response) {
 	console.log("Successfully Subscribed the email for the alert.", response);
 }
 
 // Error Callback
 let onError = function(error) {
 	console.log("Error While subscribing the email for the alert.", error);
 }
 

 // Sample call..
 swat.subscribeForProductAlert(mediumValue, medium, product, onSuccess,onError,0 ,topic);

// Define the email address you want to subscribe to
let mediumValue = "[email protected]"; // Email Address to subscribe
let medium = "email"; // Medium
let topic = "comingsoon" // the topic of "comingsoon" configured at our backend.

// Product data of the product
let product = {
 	epi: 41254709264582, // unique variant ID of the product.
 	empi: 7096252727494, // Product ID or master product ID
 	du: "https://demo.swym.it/products/1-light-pendant", // canonical product url.
 	iu: "//a.com/b.jpeg", // image url for email
 	pr: 230, // price
 }

// Success Callback
 let onSuccess = function(response) {
 	console.log("Successfully Subscribed the email for the alert.", response);
 }
 
 // Error callback
 let onError = function(error) {
 	console.log("There was an Error while subscribing the email for the alert.", error);
 }
 
 // Sample call..
 
 swat.subscribeForProductAlert(mediumValue, medium, product, onSuccess, onError,0 ,topic);

❗️

Topics are internal keywords

Please be aware that the topic parameter keywords "comingsoon" and "backinstock" are fixed and cannot be altered to something like "coming-soon." or as "back-in-stock" These are internally defined keywords; presently, this API supports only these two topics.

Differences between "comingsoon" vs "backinstock"

Topic "comingsoon" may or may not be an in-stock product; however, "backinstock" always refers to an out-of-stock product.

👍

The trigger for email may depend on your subscription plan - for more details, please visit https://swym.it/apps/back-in-stock-product-alerts/.

API Parameters

ArgumentTypeDescription
mediumValuestringValue of the medium (currently supported ‘email’, hence email Id)
mediumstringWhat id is collected (currently 'email' supported)
productobjectThe product information that the user wishes to subscribe.
successFnfunctionFunction that gets called after a successful API call
errorCallbackfunctionFunction that gets called when an error occurs
addToMailingListintPossible values: 1(opted in) or 0(opted out), to tell if user will be added to the mailing list (Note:- requires mailing list feature to be set up from Swym's end)
topicstringWe offer support for two topics: "comingsoon", which is the default if no topic is provided, and "backinstock".

Response

{"message":"Successfully added a Product alert for user"}

❗️

This API is unsuitable for headless builds - kindly use the REST version of this API .

Other Resources

product

This is a JavaScript object that contains the following keys. Each key is necessary for successfully subscribing to alerts on that product.

Property NameData TypeRequiredDescription
epiint/stringYesVariant id of the product to be added
empiint/stringYesProduct id of the product to be added
dustringYesCanonical URL of the product to be subscribed.
prnumberYesproduct price / variant price
iu stringYesimage url of the product without protocol ( "https:")