Guides and Examples
...
Products
Getting Started with Product Catalog
19 min
this guide walks you through the essential product catalog operations in the nue self service api you'll learn how to retrieve product information, understand pricing structures, and build product catalogs for your applications prerequisites before you begin, ensure you have a valid nue api key access to the nue lifecycle manager api basic understanding of rest apis and json authentication all product catalog 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"); retrieving product information the product catalog api allows you to retrieve all published products or fetch specific products by id to learn more about publishing products, please read here fetch all products try it now fetch products api ā 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"); const requestoptions = { method 'get', headers myheaders, redirect 'follow' }; fetch("https //api nue io/catalog/products", requestoptions) then(response => response json()) then(result => { console log('product catalog loaded ', result); // display each product result foreach(product => { console log(`product ${product name}`); console log(`id ${product id}`); console log(`description ${product description}`); console log(`price book entries ${product pricebookentries length}`); console log(' '); }); }) catch(error => console log('error', error)); fetch specific product try it now fetch products api ā 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 a specific product by id const productid = "01te200000b8pyeiaj"; const requestoptions = { method 'get', headers myheaders, redirect 'follow' }; fetch(`https //api nue io/catalog/products?productid=${productid}`, requestoptions) then(response => response json()) then(result => { console log('product details ', result); const product = result\[0]; // api returns array even for single product if (product) { console log(`product name ${product name}`); console log(`sku ${product sku}`); console log(`status ${product status}`); console log(`publish status ${product publishstatus}`); // display pricing information if (product pricebookentries && product pricebookentries length > 0) { console log('available pricing '); product pricebookentries foreach(entry => { console log(` ${entry currencyisocode} ${entry listprice}`); console log(` uom ${entry uom name}`); }); } } }) catch(error => console log('error', error)); understanding product structure products in the nue catalog have a rich data structure here's what you'll typically work with core product fields id unique product identifier name display name for the product description detailed product description sku stock keeping unit identifier status product status (active, inactive, etc ) publishstatus whether the product is published for self service pricing information each product includes pricebookentries that contain listprice base price for the product currencyisocode currency (usd, eur, etc ) uom unit of measure (user/month, license, etc ) active whether this pricing is currently active product features and options productfeatures available features for this product productoptions configurable options for bundles configurable whether the product has configurable options building a product catalog display here's a practical example of building a product catalog for your application async function buildproductcatalog() { const myheaders = new headers(); myheaders append("nue api key", "your api key here"); myheaders append("content type", "application/json"); try { const response = await fetch("https //api nue io/catalog/products", { method 'get', headers myheaders }); const products = await response json(); // filter only published products const publishedproducts = products filter(product => product publishstatus === 'published' && product status === 'active' ); // build catalog display const catalog = publishedproducts map(product => ({ id product id, name product name, description product description, sku product sku, imageurl product imageurl, pricing product pricebookentries map(entry => ({ price entry listprice, currency entry currencyisocode, unitofmeasure entry uom name, recommended entry recommended })), features product productfeatures || \[], isbundle product configurable, bundleoptions product productoptions || \[] })); console log('catalog ready for display ', catalog); return catalog; } catch (error) { console error('failed to load product catalog ', error); throw error; } } // usage buildproductcatalog() then(catalog => { // render your product catalog ui catalog foreach(product => { console log(`š¦ ${product name}`); console log(` ${product description}`); product pricing foreach(price => { const badge = price recommended ? ' (recommended)' ''; console log(` š° ${price currency} ${price price}/${price unitofmeasure}${badge}`); }); if (product isbundle) { console log(` š§ configurable bundle with ${product bundleoptions length} options`); } console log(''); }); }); filtering and searching products for better user experience, you'll want to implement filtering and search function filterproducts(products, filters = {}) { return products filter(product => { // filter by name/description search if (filters search) { const searchterm = filters search tolowercase(); const matchesname = product name tolowercase() includes(searchterm); const matchesdescription = product description? tolowercase() includes(searchterm); if (!matchesname && !matchesdescription) return false; } // filter by price range if (filters minprice || filters maxprice) { const prices = product pricebookentries map(entry => entry listprice); const minproductprice = math min( prices); const maxproductprice = math max( prices); if (filters minprice && maxproductprice < filters minprice) return false; if (filters maxprice && minproductprice > filters maxprice) return false; } // filter by product type if (filters bundlesonly && !product configurable) return false; if (filters simpleproductsonly && product configurable) return false; return true; }); } // usage example const allproducts = await buildproductcatalog(); // search for "professional" products under $100 const filteredproducts = filterproducts(allproducts, { search 'professional', maxprice 100 }); console log(`found ${filteredproducts length} matching products`); handling bundle products bundle products have special considerations for configuration and automatic order product creation important bundle behavior critical when ordering bundle products with required product options (add ons) explicitly configured add ons are created exactly as specified in your order required but unconfigured add ons are automatically created with default quantities optional add ons are only created if explicitly included in the order this ensures customers receive complete bundle functionality even if not all required components are explicitly configured in the order request the system automatically provisions missing required components to maintain bundle integrity // example bundle with required add ons const bundleorder = { "orderproducts" \[ { "pricebookentryid" "01uea00000f9jpqiav", // salesforce price book entry id "quantity" 1, "addons" \[ { "productoptionid" "01oea00000g8kqriav", // salesforce product option id "productoptionquantity" 2 } // note if this bundle has required add ons not listed here, // they will be automatically created as separate order products // with default quantities to ensure complete bundle functionality ] } ] }; // result order creates multiple order products // 1 main bundle product (as specified) // 2 optional add on (as configured) // 3 required add on a (auto created with default quantity) // 4 required add on b (auto created with default quantity) bundle analysis and configuration function analyzebundleproduct(product) { if (!product configurable || !product productoptions) { return { isbundle false }; } const bundleinfo = { isbundle true, baseproduct { name product name, description product description, basepricing product pricebookentries }, options product productoptions map(option => ({ id option id, name option name, description option description, required option required, optiontype option optiontype, defaultquantity option defaultquantity || 1, // additional option details would be here })), requiredoptions product productoptions filter(option => option required), optionaloptions product productoptions filter(option => !option required) }; return bundleinfo; } // example usage for bundle handling async function displaybundledetails(productid) { const response = await fetch(`https //api nue io/catalog/products?productid=${productid}`, { method 'get', headers myheaders }); const products = await response json(); const product = products\[0]; const bundleinfo = analyzebundleproduct(product); if (bundleinfo isbundle) { console log(`š¦ bundle ${bundleinfo baseproduct name}`); if (bundleinfo requiredoptions length > 0) { console log('\nš“ required options (auto created if not configured) '); bundleinfo requiredoptions foreach(option => { console log(` ⢠${option name} (default qty ${option defaultquantity})`); console log(` ${option description}`); }); } if (bundleinfo optionaloptions length > 0) { console log('\nš¢ optional add ons (only created if explicitly included) '); bundleinfo optionaloptions foreach(option => { console log(` ⢠${option name}`); console log(` ${option description}`); }); } console log('\nš” tip required options will be automatically added to orders even if not explicitly configured, ensuring complete bundle functionality '); } else { console log(`š¦ simple product ${product name}`); } } common patterns and best practices 1\ error handling always implement proper error handling for your product catalog operations async function safeproductfetch(productid = null) { try { const url = productid ? `https //api nue io/catalog/products?productid=${productid}` 'https //api nue io/catalog/products'; const response = await fetch(url, { method 'get', headers myheaders }); if (!response ok) { throw new error(`http error! status ${response status}`); } const products = await response json(); if (productid && products length === 0) { throw new error(`product ${productid} not found or not published`); } return products; } catch (error) { console error('product fetch error ', error); // return empty array for graceful degradation return \[]; } } 2\ caching product data product catalogs don't change frequently, so implement caching class productcatalogcache { constructor(ttlminutes = 30) { this cache = new map(); this ttl = ttlminutes 60 1000; // convert to milliseconds } set(key, data) { this cache set(key, { data, timestamp date now() }); } get(key) { const cached = this cache get(key); if (!cached) return null; // check if cache has expired if (date now() cached timestamp > this ttl) { this cache delete(key); return null; } return cached data; } async getproducts() { const cached = this get('all products'); if (cached) { console log('using cached product data'); return cached; } console log('fetching fresh product data'); const products = await safeproductfetch(); this set('all products', products); return products; } } // usage const catalogcache = new productcatalogcache(30); // 30 minute cache const products = await catalogcache getproducts(); 3\ performance optimization for large catalogs, implement pagination and lazy loading function paginateproducts(products, page = 1, pagesize = 20) { const startindex = (page 1) pagesize; const endindex = startindex + pagesize; return { products products slice(startindex, endindex), totalproducts products length, totalpages math ceil(products length / pagesize), currentpage page, hasnextpage endindex < products length, haspreviouspage page > 1 }; } // usage const allproducts = await catalogcache getproducts(); const page1 = paginateproducts(allproducts, 1, 10); console log(`showing ${page1 products length} of ${page1 totalproducts} products`); next steps now that you understand basic product catalog operations, you can learn about pricing structures in the product data model guide understand publishing workflows for managing product availability explore bundle configuration for complex product offerings build shopping experiences with product selection and ordering move on to product data model to learn about all available product fields and their relationships, or key considerations for products to understand best practices for self service product catalogs