Add many products to a list

Add many products to a List. (Many products to a single list)

swat.addProductsToList

Add many Products to a List with the given lid.

Definition

swat.addProductsToList(lid, products, onSuccess, onError)

Example

Here's an example of how you can use this API to add many Products into a List called black friday list:

// Define the list id of the list
let lid = "59179e9f-139d-4857-bcdd-3ad88a38b47d" // List ID 

// Define the products array with 2 products.
let products = [{
	du: "https://demo.swym.it/products/1300mm-ceiling-fan",
	empi: 7096402444486,
	epi: 41255088488646,
}, {
	du: "https://demo.swym.it/products/1200-mm-48-inch-high-speed-ceiling-fan-white",
	empi: 7096259772614,
	epi: 41254731120838
}]

// Define success callback
let onSuccess = function (response){
  // Successfully added many list items 
  // Response will contain the list items added to the list
  console.log(`Successfully added many Products to the List ${lid}`, response);
}

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

// `addProductsToList` call
swat.addProductsToList(lid, products, onSuccess, onError);

👍

Things to Consider

  1. This API is useful when you want to add many products to a List on a single network request..
  2. You can add upto 10 products in a single request.
  3. You cannot add invalid products.

API Parameters

ArgumentTypeDescription
lidguidUnique id of the List to fetch contents
productsarrayArray of Products
Array length - Max 10 at a time as it affects response times
onSuccessfunctionCalled when the Products are successfully added.
onErrorfunctionCalled when there is an error while adding many Products to the List.

Success Response

[{
		"di": "fb283019-487b-4447-99e6-133178f6477e",
		"bt": "Swym Marketing",
		"dt": "1300mm Ceiling Fan",
		"cts": 1679659226185,
		"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": 1679659226185,
		"_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": "1200 mm (48 inch) High Speed Ceiling Fan (White)",
		"cts": 1679659226233,
		"empi": 7096259772614,
		"sku": "35",
		"lid": "b62abea5-370a-4111-aed7-4d7752ff87b7",
		"du": "https://demo.swym.it/products/1200-mm-48-inch-high-speed-ceiling-fan-white",
		"pid": "KABSbuGyYCuM6/IV7e7cGxT1978LieU1jRdMt6XhYfo=",
		"epi": 41254731120838,
		"uts": 1679659226233,
		"_pkey": "fb283019",
		"iu": "https://cdn.shopify.com/s/files/1/0534/3635/0662/products/1200mm_48inch_DecorativeCeilingFanwithLights_620x620.jpg?v=1637589184",
		"_t": 2,
		"pr": 800.0
	}]

Other References

Product

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

let product = {
  epi: epi, // unique variant id of the product
  empi: empi, // master id of the product
  du: du, // product url
  qty: qty, // optional 
  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