Add product to many lists

Add a product to many lists. (Add a single product to many lists)

swat.addProductToLists

Add a single Product to many Lists.

Definition

swat.addProductToLists(product, lists, onSuccess, onError)

Example

Here's an example of how you can use this API to add a product into many Lists :

// list item object to be added to lists.
var product = { // item 
  epi: epi,  // unique variant of the product per listid
  empi: empi, // product id 
  du: du // product url. 
}

let lists = [`listId1`, `listId2`]; // guids of the lists to add to max 10 at a time.

// Define success callback
let onSuccess = function (response){
  // Successfully added an item to many lists (1 item to : many lists)
  // response will contain the list items added to the lists
  console.log("Successfully added a product to many lists", response);
}

// Define error callback
let onError = function (error){
  // Error is an xhrObj
  console.log("Error while adding a product to many lists", error);
}

swat.addProductToLists(product, lists, onSuccess, onError);

👍

Things to consider

  1. This API is useful if you want to add a single product to multiple lists. (1 : N )
  2. You may only add a single product to a maximum of 10 lists on a single request.
  3. Please fetch the lists and check if the lists that the user wants to add are present before adding.
  4. You can also chain it with the create list API.
  5. The default wishlist has a list selection UI, which is a prime example of this API. You can check out the demo at demo.swym.it.

API Parameters

ArgumentTypeDescription
listsarrayArray of List ids into which the Product should be added.
Array length - Max 10 at a time as it affects response times
productobjectPlease refer Product
onSuccessfunctionCalled when the Product is successfully added to many Lists.
onErrorfunctionCalled when there is an error while adding a Product to many Lists.

Success Response

[
        {
            "di": "fb283019-487b-4447-99e6-133178f6477e",
            "bt": "Swym Marketing",
            "dt": "1300mm Ceiling Fan",
            "cts": 1679658412978,
            "empi": 7096402444486,
            "sku": "35",
            "lid": "b62abea5-370a-4111-aed7-4d7752ff87b7",
            "du": "https://demo.swym.it/products/1300mm-ceiling-fan",
            "pid": "KABSbuGyYCuM6/IV7e7cGxT1978LieU1jRdMt6XhYfo=",
            "epi": 41255088488646,
            "uts": 1679658412978,
            "_pkey": "fb283019",
            "iu": "https://cdn.shopify.com/s/files/1/0534/3635/0662/products/1300mmCeilingFan_620x620.jpg?v=1637592943",
            "_t": 2,
            "pr": 800.0
        },
        {
            "di": "fb283019-487b-4447-99e6-133178f6477e",
            "bt": "Swym Marketing",
            "dt": "1300mm Ceiling Fan",
            "cts": 1679658413039,
            "empi": 7096402444486,
            "sku": "35",
            "lid": "313bef26-16b4-4861-be1b-c986f6ac5871",
            "du": "https://demo.swym.it/products/1300mm-ceiling-fan",
            "pid": "KABSbuGyYCuM6/IV7e7cGxT1978LieU1jRdMt6XhYfo=",
            "epi": 41255088488646,
            "uts": 1679658413039,
            "_pkey": "fb283019",
            "iu": "https://cdn.shopify.com/s/files/1/0534/3635/0662/products/1300mmCeilingFan_620x620.jpg?v=1637592943",
            "_t": 2,
            "pr": 800.0
        }
    ]

Other References

Product

An object containing params required for creating, updating or deleting list items

let product = {
  epi: epi, // one unique list item (empi+epi) per listid
  empi: empi,
  du: du,
  qty: qty,
  note: note, //optional
  cprops: {} // Optional custom attributes
};
--data-urlencode 'epi: {{epi}}' \ # One unique list item (empi+epi) per listid
--data-urlencode 'empi: {{empi}}' \ 
--data-urlencode 'du: {{du}}' \
--data-urlencode 'qty: {{qty}}' \
--data-urlencode 'note: {{note}}' \
--data-urlencode 'cprops: {{JSON stringified cprops}}' \ # Optional custom attributes
Property NameData TypeRequiredDescription
product.epiint/stringYesVariant id of the product to be added
product.empiint/stringYesProduct id of the product to be added
product.dustringYesCanonical uri of the product to be added
product.qtyintoptionalDefaults to 1. Quantity included for the add action
product.notestringoptionalOptional note
product.cpropsobjectoptionalMap of custom fields
product.lblsarrayoptionalArray of strings indicating labels, rooms, etc. for HTC. Only one value supported in array. eg: ["Room1"]
product._avbooloptionaltrue if the list action was done without user explicitly picking a variant. Can be used by Wishlist UX to require user to pick variant before adding to cart