Guides and Examples
...
Products
Fetching Products
18 min
this guide provides comprehensive instructions for retrieving product data using the nue lifecycle management api learn how to fetch all products or retrieve individual products by id prerequisites before you begin, ensure you have a valid nue api key basic understanding of rest apis and json familiarity with product data structures authentication all product operations require authentication using your nue api key in the nue api key header const myheaders = new headers(); myheaders append("nue api key", "your api key here"); myheaders append("content type", "application/json"); product retrieval methods fetch all products try it now fetch products → https //api docs nue io/fetch product const myheaders = new headers(); myheaders append("nue api key", "your api key here"); myheaders append("content type", "application/json"); // fetch all published products fetch('https //api nue io/catalog/products', { method 'get', headers myheaders }) then(response => response json()) then(products => { console log(`retrieved ${products length} products`); products foreach(product => { console log(`\n ${product name} `); console log(`id ${product id}`); console log(`sku ${product sku}`); console log(`status ${product status}`); console log(`publish status ${product publishstatus}`); console log(`description ${product description || 'no description'}`); // display pricing information if (product pricebookentries && product pricebookentries length > 0) { console log('available pricing '); product pricebookentries foreach(entry => { console log(` ${entry currencyisocode} ${entry listprice}/${entry uom name}`); }); } // display bundle information if applicable if (product configurable && product productoptions) { console log(`bundle components ${product productoptions length} options`); } }); }) catch(error => console log('error ', error)); fetch single product by id retrieve a specific product with detailed information // use a real salesforce product id const productid = "01tea00000e8ipuiav"; fetch(`https //api nue io/catalog/products?productid=${productid}`, { method 'get', headers myheaders }) then(response => response json()) then(products => { if (products length > 0) { const product = products\[0]; // api returns array even for single product console log('✅ product found '); console log(`name ${product name}`); console log(`sku ${product sku}`); console log(`id ${product id}`); console log(`status ${product status}`); console log(`publish status ${product publishstatus}`); // display detailed product information console log(`\nproduct details `); console log(` description ${product description || 'not provided'}`); console log(` record type ${product recordtype}`); console log(` price model ${product pricemodel}`); console log(` configurable ${product configurable ? 'yes' 'no'}`); // display pricing options if (product pricebookentries && product pricebookentries length > 0) { console log(`\npricing options `); product pricebookentries foreach(entry => { const recommended = entry recommended ? ' ⭐' ''; console log(` ${entry currencyisocode} ${entry listprice}/${entry uom name}${recommended}`); }); } // display availability console log(`\navailability `); console log(` start date ${product startdate || 'not set'}`); console log(` end date ${product enddate || 'no expiration'}`); // display bundle information if (product configurable && product productoptions) { console log(`\nbundle information `); console log(` components ${product productoptions length} options`); product productoptions foreach((option, index) => { console log(` ${index + 1} ${option optionname} (required ${option required})`); }); } } else { console log('❌ product not found'); } }) catch(error => console log('error ', error)); advanced product management product catalog manager build a comprehensive product catalog with advanced search and categorization class productcatalogmanager { constructor(apikey) { this apikey = apikey; this headers = new headers(); this headers append("nue api key", apikey); this headers append("content type", "application/json"); this productcache = new map(); } async buildproductcatalog() { try { console log('📦 building product catalog '); // fetch all published products const response = await fetch('https //api nue io/catalog/products', { method 'get', headers this headers }); if (!response ok) { throw new error(`failed to fetch products ${response status}`); } const products = await response json(); // build comprehensive catalog const catalog = { products products, bycategory {}, byrecordtype {}, bycurrency {}, bystatus { active \[], inactive \[] }, bundles \[], recurringproducts \[], statistics { totalproducts products length, activeproducts 0, inactiveproducts 0, bundleproducts 0, recurringproducts 0, categories new set(), currencies new set(), averageprice 0, pricerange { min null, max null } } }; let totalprice = 0; let pricecount = 0; products foreach(product => { // categorize by category if (product productcategory) { if (!catalog bycategory\[product productcategory]) { catalog bycategory\[product productcategory] = \[]; } catalog bycategory\[product productcategory] push(product); catalog statistics categories add(product productcategory); } // categorize by record type if (product recordtype) { if (!catalog byrecordtype\[product recordtype]) { catalog byrecordtype\[product recordtype] = \[]; } catalog byrecordtype\[product recordtype] push(product); } // categorize by currency from price book entries if (product pricebookentries && product pricebookentries length > 0) { product pricebookentries foreach(entry => { if (entry currencyisocode) { if (!catalog bycurrency\[entry currencyisocode]) { catalog bycurrency\[entry currencyisocode] = \[]; } if (!catalog bycurrency\[entry currencyisocode] includes(product)) { catalog bycurrency\[entry currencyisocode] push(product); } catalog statistics currencies add(entry currencyisocode); } }); } // categorize by status if (product status === 'active') { catalog bystatus active push(product); catalog statistics activeproducts++; } else { catalog bystatus inactive push(product); catalog statistics inactiveproducts++; } // track bundles if (product configurable) { catalog bundles push(product); catalog statistics bundleproducts++; } // track recurring products if (product pricemodel === 'recurring') { catalog recurringproducts push(product); catalog statistics recurringproducts++; } // price analysis from price book entries if (product pricebookentries && product pricebookentries length > 0) { product pricebookentries foreach(entry => { if (entry listprice) { const price = parsefloat(entry listprice); totalprice += price; pricecount++; if (catalog statistics pricerange min === null || price < catalog statistics pricerange min) { catalog statistics pricerange min = price; } if (catalog statistics pricerange max === null || price > catalog statistics pricerange max) { catalog statistics pricerange max = price; } } }); } // cache product for quick lookup this productcache set(product id, product); }); // calculate average price if (pricecount > 0) { catalog statistics averageprice = totalprice / pricecount; } // display catalog summary console log('\n📊 product catalog summary '); console log(` total products ${catalog statistics totalproducts}`); console log(` active ${catalog statistics activeproducts}`); console log(` inactive ${catalog statistics inactiveproducts}`); console log(` bundles ${catalog statistics bundleproducts}`); console log(` recurring ${catalog statistics recurringproducts}`); console log(` categories ${catalog statistics categories size}`); console log(` currencies ${array from(catalog statistics currencies) join(', ')}`); if (catalog statistics averageprice > 0) { console log(` average price $${catalog statistics averageprice tofixed(2)}`); console log(` price range $${catalog statistics pricerange min} $${catalog statistics pricerange max}`); } console log(`\n📦 products by record type `); object entries(catalog byrecordtype) sort((\[,a], \[,b]) => b length a length) foreach((\[recordtype, products]) => { console log(` ${recordtype} ${products length} products`); }); console log(`\n🏷️ products by category `); object entries(catalog bycategory) sort((\[,a], \[,b]) => b length a length) foreach((\[category, products]) => { console log(` ${category} ${products length} products`); }); return catalog; } catch (error) { console error('failed to build product catalog ', error); throw error; } } async getproductbyid(productid) { // check cache first if (this productcache has(productid)) { return this productcache get(productid); } try { const response = await fetch(`https //api nue io/catalog/products?productid=${productid}`, { method 'get', headers this headers }); if (!response ok) { throw new error(`failed to fetch product ${response status}`); } const products = await response json(); if (products length > 0) { const product = products\[0]; this productcache set(productid, product); return product; } return null; } catch (error) { console error(`failed to fetch product ${productid} `, error); return null; } } searchproducts(catalog, searchterm) { const term = searchterm tolowercase(); return catalog products filter(product => { return product name? tolowercase() includes(term) || product sku? tolowercase() includes(term) || product description? tolowercase() includes(term) || product productcategory? tolowercase() includes(term); }); } getproductsbycategory(catalog, category) { return catalog bycategory\[category] || \[]; } getactiveproductsinpricerange(catalog, minprice, maxprice, currency = null) { return catalog bystatus active filter(product => { if (!product pricebookentries || product pricebookentries length === 0) return false; return product pricebookentries some(entry => { if (currency && entry currencyisocode !== currency) return false; if (!entry listprice) return false; const price = parsefloat(entry listprice); return price >= minprice && price <= maxprice; }); }); } getbundleproducts(catalog) { return catalog bundles; } getrecurringproducts(catalog) { return catalog recurringproducts; } } // usage const catalogmanager = new productcatalogmanager("your api key here"); catalogmanager buildproductcatalog() then(catalog => { console log('\n📦 product catalog built successfully'); // search example const searchresults = catalogmanager searchproducts(catalog, 'platform'); console log(`\n🔍 search for "platform" ${searchresults length} results`); // get products by category const firstcategory = object keys(catalog bycategory)\[0]; if (firstcategory) { const categoryproducts = catalogmanager getproductsbycategory(catalog, firstcategory); console log(`\n🏷️ ${firstcategory} category ${categoryproducts length} products`); } // get products in price range const pricerangeproducts = catalogmanager getactiveproductsinpricerange(catalog, 100, 1000, 'usd'); console log(`\n💰 products $100 $1000 ${pricerangeproducts length} products`); return catalog; }); error handling and best practices robust product fetching async function safeproductfetch(productid = null) { const myheaders = new headers(); myheaders append("nue api key", "your api key here"); myheaders append("content type", "application/json"); try { // build url based on whether we want all products or specific product const url = productid ? `https //api nue io/catalog/products?productid=${productid}` 'https //api nue io/catalog/products'; // validate salesforce id format if productid provided if (productid) { const salesforceidregex = /^\[a za z0 9]{15,18}$/; if (!salesforceidregex test(productid)) { throw new error(`invalid salesforce id format ${productid}`); } } const response = await fetch(url, { method 'get', headers myheaders, timeout 30000 // 30 second timeout }); if (!response ok) { throw new error(`http ${response status} ${response statustext}`); } const products = await response json(); // validate response if (!array isarray(products)) { throw new error('invalid response format expected array'); } // check for missing product when specific id requested if (productid && products length === 0) { throw new error(`product ${productid} not found or not published`); } return { products, found products length, requested productid ? 1 'all', error null }; } catch (error) { console error('product fetch error ', error); return { products \[], found 0, requested productid ? 1 'all', error error message }; } } // usage with error handling safeproductfetch("01tea00000e8ipuiav") then(result => { if (result error) { console error('fetch failed ', result error); } else { console log(`successfully fetched ${result found} product(s)`); result products foreach(product => { console log(` ${product name} (${product id})`); }); } }); query parameters reference parameter type required description example productid string no salesforce product id to retrieve specific product "01tea00000e8ipuiav" response structure product object fields core identity id unique product identifier (salesforce id) name product name sku sku or product code description product description status product status (active, inactive, draft) publishstatus publish status for self service product classification recordtype product record type (product, service, bundle) productcategory product category classification configurable whether product has configuration options pricing information pricebookentries array of pricing options listprice price amount currencyisocode currency code uom unit of measure object active whether pricing is active recommended whether pricing is recommended bundle information (if configurable) productoptions array of bundle components bundletemplate bundle behavior model common use cases product catalog display // build product catalog for display const catalog = await catalogmanager buildproductcatalog(); // enable search and filtering features single product details // get detailed product information const product = await catalogmanager getproductbyid("01tea00000e8ipuiav"); // display product details and pricing search and filtering // search products by term const results = catalogmanager searchproducts(catalog, "platform"); // filter by category or price range performance optimization efficient product operations cache products store frequently accessed product information validate ids client side validation of salesforce id format error recovery implement graceful handling of missing products single api calls fetch all products once, then search/filter locally rate limiting respect limits 1000 requests per minute in production implement backoff use exponential backoff for retry logic monitor usage track api consumption patterns this guide enables you to efficiently retrieve and manage product data using the nue lifecycle management api, supporting both bulk catalog operations and individual product lookups with proper salesforce id handling