Get Products
Usage
Fetch product data by product IDs.
By default, this method retrieves products through the recommendations engine (recently viewed). To fetch products directly by their IDs without going through the recommendations engine, use the direct: true option.
Example (Direct Fetch - Recommended)
window.FastSimonSDK.getProducts({
productIds: ["123","456","234235"],
direct: true,
callback: (result) => {
// handle here
}
});
Example (Promise)
const products = await window.FastSimonSDK.getProducts({
productIds: ["123","456","234235"],
direct: true
});
Example (Default - via Recommendations)
// Legacy behavior: fetches products through the recommendations engine.
// Products must be indexed and the recently-viewed widget must be configured.
window.FastSimonSDK.getProducts({
productIds: ["123","456","234235"],
callback: (result) => {
// handle here
}
});
Options
| Option | Type | Description |
|---|---|---|
| productIds | string[] (required) | A list of product id's to fetch |
| callback | (Response) => void (required when promise is not used) | Callback to handle the results |
| direct | boolean | When true, fetches products directly by ID. Recommended for most use cases. Default: false (uses recommendations engine) |
| withAttributes | boolean | When true, includes product attributes in the response. Only available with direct: true |
| withBadges | boolean | When true, appends a badges array to each product with the matched site badges. Automatically enables withAttributes. |
Response
type Response = Product[]
Getting All Product Images via Custom Attributes
By default, each product includes:
product.t— main/thumbnail image URLproduct.t2— fallback image URL
To retrieve all product images, the Fast Simon team must first enable the "Product images" custom attribute for your store. This is a server-side configuration — it is not self-service.
To request this: Contact support@fastsimon.com and ask to enable product images as a custom attribute.
Once enabled, use withAttributes: true with direct: true to receive the full image list:
window.FastSimonSDK.getProducts({
productIds: ["123", "456"],
direct: true,
withAttributes: true,
callback: (products) => {
products.forEach((product) => {
const imagesAttr = product.attributes?.find(([key]) => key === "Product images");
const allImages = imagesAttr ? imagesAttr[1] : [];
console.log("All images for", product.l, ":", allImages);
});
}
});
The attributes field is an array of [attributeName, values] tuples. The "Product images" entry contains an array of all image URLs for the product.