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 categorized based on topic (either 'backinstock' or 'comingsoon'). When conditions for these topics are met, subscribers registered via this API will receive an alert email or sms depending on the medium value used to subscribe to the alert.
// Define the email address you want to subscribe to
let mediumValue = "[email protected]"; // Email Address to subscribe
let medium = "email"; // 'email' or 'sms'
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
Argument | Type | Description |
---|---|---|
mediumValue | string | Value of the medium (email or phone number) |
medium | string | What ID is collected ('email' or 'sms' supported) |
product | object | The product information that the user wishes to subscribe. |
successFn | function | Function that gets called after a successful API call |
errorCallback | function | Function that gets called when an error occurs |
addToMailingList | int | Possible values: 1(opted in) or 0(opted out), to tell if the user will be added to the mailing list (Note:- requires mailing list feature to be set up from Swym's end) |
topic | string | We 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 Name | Data Type | Required | Description |
---|---|---|---|
epi | int/string | Yes | Variant id of the product to be added |
empi | int/string | Yes | Product id of the product to be added |
du | string | Yes | Canonical URL of the product to be subscribed. |
pr | number | Yes | product price / variant price |
iu | string | Yes | image url of the product without protocol ( "https:") |
Updated about 1 month ago