Fetching Customer Products
14 min
this guide covers the customer scoped product catalog endpoint ( get /customers/{customerid}/products ), which returns products filtered to only the price book entries relevant to a specific customer based on their account level pricing attributes prerequisites before you begin, ensure you have a valid nue api key a customer id (nue id or salesforce external id) products published with pricing attributes configured in the catalog basic knowledge of rest apis and json when to use this endpoint use get /customers/{customerid}/products instead of get /catalog/products when you need to show a customer only the products and pricing tiers they are eligible for this is especially useful for self service portals and customer facing storefronts where different customer segments see different product offerings get /catalog/products — returns the full published catalog with all price book entries get /customers/{customerid}/products — returns the catalog filtered to only the price book entries that match the customer's account attributes authentication all requests 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"); how filtering works the endpoint evaluates each price book entry's pricing attributes against the customer's account fields rule behavior no pricing attributes price book entry is universal — always included for every customer account level attributes attributes mapped to quote accountid {fieldname} are resolved against the customer's account fields all account level conditions must match for the pbe to be included any wildcard a pricing attribute with value any matches any customer, regardless of the customer's field value quote level attributes attributes not mapped to quote accountid are ignored at catalog level — they are evaluated at order time product exclusion products with zero matching price book entries after filtering are excluded from the response entirely bundle options product options within bundles are filtered by the same rules options whose pbe does not match are removed example given a catalog with pricing attributes based on the customer's type field product pbe pricing attribute matches "channel partner" matches "prospect" platform license standard (none) yes (universal) yes (universal) platform license partner tier quote accountid type = channel partner yes no support license enterprise quote accountid type = enterprise no no a customer with type = "channel partner" would see platform license with both pbes (standard + partner tier) a prospect would see platform license with only the standard pbe support license would be excluded for both since the enterprise pbe does not match either customer type fetching customer products basic example fetch the filtered product catalog for a specific customer const myheaders = new headers(); myheaders append("nue api key", "your api key here"); myheaders append("content type", "application/json"); const customerid = "d2e04653 ae90 49df a986 134cf64f6d03"; fetch(`https //api nue io/customers/${customerid}/products`, { method 'get', headers myheaders }) then(response => response json()) then(result => { console log(`status ${result status}`); console log(`products available ${result data length}`); result data foreach(product => { console log(`\n ${product name} `); console log(`sku ${product sku}`); console log(`price book entries ${product pricebookentries length}`); product pricebookentries foreach(pbe => { console log(` ${pbe uom name} $${pbe listprice} (${pbe currencyisocode})`); }); // display bundle options if applicable if (product configurable && product productoptions) { console log(`bundle options ${product productoptions length}`); product productoptions foreach(opt => { console log(` ${opt product? name || opt productoptionid}`); }); } }); }) catch(error => console log('error ', error)); scoping the request with productids by default this endpoint reads the entire published catalog before filtering it on a large catalog that single read can exceed the upstream response size limit and the request fails with http 500 if you already know which products you want to show, pass their ids and only those products are fetched const productids = \[ "01tqc00000iu1ofyab", "01tqc00000kbr8jyad", "01tqc00000kvuxlyap" ]; const url = `https //api nue io/customers/${customerid}/products` \+ `?productids=${encodeuricomponent(json stringify(productids))}`; fetch(url, { method 'get', headers myheaders }) then(response => response json()) then(result => { console log(`products returned ${result data length}`); // ids that could not be returned are reported rather than silently dropped result warnings foreach(w => console log(`${w\ code} ${w\ message}`)); }) catch(error => console log('error ', error)); a few things worth knowing before you use it these are product ids, not skus if you maintain your catalog list as skus, map them to ids once and store the result there is no sku filter on this endpoint the value must be a json array of strings double quotes are required \[] , a value that is not valid json, and a non string element each return 400 invalid parameter repeated ids are de duplicated , so passing the same id twice costs one lookup a product you asked for may not come back if the id does not resolve, or the customer has no matching price book entry for it, the request still returns 200 and the id is listed in a products not found warning read warnings rather than assuming data mirrors your request customer filtering still applies scoping changes which products are fetched, not how they are filtered the pricing attribute rules above are applied exactly as they are without the parameter omit the parameter entirely to keep the original behaviour of returning the whole catalog using a salesforce external id the endpoint accepts either a nue customer id or a salesforce account id const salesforceaccountid = "001em00001f0992iab"; fetch(`https //api nue io/customers/${salesforceaccountid}/products`, { method 'get', headers myheaders }) then(response => response json()) then(result => { console log(`products for sf account ${result data length}`); }) catch(error => console log('error ', error)); building a customer storefront use the filtered catalog to build a product selection ui where customers only see what they are eligible to purchase async function loadstorefront(customerid) { const response = await fetch( `https //api nue io/customers/${customerid}/products`, { method 'get', headers myheaders } ); const result = await response json(); if (result status !== 'success') { console error('failed to load catalog ', result); return; } const standaloneproducts = result data filter(p => !p configurable); const bundles = result data filter(p => p configurable); console log('standalone products '); standaloneproducts foreach(p => { const entry = p pricebookentries\[0]; console log(` ${p name} — $${entry listprice}/${entry uom name}`); }); console log('\nbundles '); bundles foreach(p => { console log(` ${p name}`); p productoptions? foreach(opt => { const type = opt bundled ? 'included' opt required ? 'required' 'optional'; console log(` \[${type}] ${opt product? name}`); }); }); } loadstorefront("d2e04653 ae90 49df a986 134cf64f6d03"); response reference the response shape is identical to get /catalog/products , wrapped in the standard self service response envelope field type description status string "success" or "error" data array array of product objects, filtered to only those with matching price book entries warnings array any warnings generated during processing each product in data has the same schema as get /catalog/products — including pricebookentries , productoptions , productfeatures , and all standard product fields the only difference is that non matching price book entries and product options have been removed error responses status error code description 404 customer not found no customer found with the provided id 401 unauthorized invalid or missing api key 400 invalid parameter productids was supplied but is not a json array of non empty strings an empty array is also rejected warnings warnings are returned alongside a successful response rather than replacing it code description products not found one or more ids passed in productids were not returned, either because the id does not resolve or because the customer has no matching price book entry for that product the message lists the affected ids