Guides and Examples
...
Price and Discount Tags
Getting Started with Price Tags
17 min
this guide walks you through the essential price tag operations in the nue self service api you'll learn how to retrieve price tag information, understand pricing structures, and implement dynamic pricing 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 published price tags in your nue environment (only published price tags appear in the api) authentication all price tag 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"); understanding price tags price tags are powerful pricing rules that modify base product prices through volume discounts based on quantity purchased term discounts based on subscription length tiered pricing with different rates at different levels time limited promotions with start and end dates retrieving price tag information the price tag api allows you to fetch all published price tags or specific tags by id to learn more about publishing price tags, please read here fetch all price tags try it now fetch price tags api → https //api docs nue io/fetch price tag 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/price tags", requestoptions) then(response => response json()) then(result => { console log('price tags loaded ', result); // display each price tag result foreach(pricetag => { console log(`price tag ${pricetag name}`); console log(`code ${pricetag code}`); console log(`type ${pricetag pricetagtype}`); console log(`active ${pricetag active}`); console log(`tiers ${pricetag pricetiers length}`); console log(' '); }); }) catch(error => console log('error', error)); fetch specific price tag try it now fetch price tags api → https //api docs nue io/fetch price tag const myheaders = new headers(); myheaders append("nue api key", "your api key here"); myheaders append("content type", "application/json"); // fetch a specific price tag by code const pricetagcode = "fft"; const requestoptions = { method 'get', headers myheaders, redirect 'follow' }; fetch(`https //api nue io/catalog/price tags/${pricetagcode}`, requestoptions) then(response => response json()) then(result => { console log('price tag details ', result); const pricetag = result\[0]; // api returns array even for single price tag if (pricetag) { console log(`price tag name ${pricetag name}`); console log(`code ${pricetag code}`); console log(`description ${pricetag description}`); console log(`price type ${pricetag pricetype}`); console log(`publish status ${pricetag publishstatus}`); // display pricing tiers if (pricetag pricetiers && pricetag pricetiers length > 0) { console log('pricing tiers '); pricetag pricetiers foreach((tier, index) => { console log(` tier ${index + 1} `); console log(` range ${tier startunit || 0} ${tier endunit || '∞'}`); console log(` charge model ${tier chargemodel}`); if (tier discountpercentage) { console log(` discount ${tier discountpercentage}%`); } if (tier amount) { console log(` amount $${tier amount}`); } }); } } }) catch(error => console log('error', error)); understanding price tag structure price tags in the nue catalog have a comprehensive data structure here's what you'll typically work with core price tag fields id unique price tag identifier (salesforce price tag id) name display name for the price tag code unique code for api references and promotions (used for fetching individual price tags) description detailed explanation of the pricing rule active whether the price tag is currently active publishstatus whether the price tag is published for self service (only "published" price tags appear in api responses) pricing configuration pricetagtype "quantity" or "term" based pricing pricetype "volume", "tiered", or "ramp" pricing model uomdimension unit of measure (user, license, etc ) starttime when the pricing becomes effective endtime when the pricing expires (optional) price tiers each price tag contains pricetiers that define specific pricing rules chargemodel "perunit" or "flatfee" startunit beginning of tier range endunit end of tier range amount price amount for price tags discountpercentage percentage discount for discount tags building a price tag display here's a practical example of building a price tag display for your application async function buildpricetagcatalog() { 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/price tags", { method 'get', headers myheaders }); const pricetags = await response json(); // note only published price tags are returned by the api // filter only active price tags (publishstatus will always be 'published') const activepricetags = pricetags filter(tag => tag active); // organize price tags by type const organizedtags = { volume \[], term \[], promotional \[] }; activepricetags foreach(tag => { const taginfo = { id tag id, name tag name, code tag code, description tag description, type tag pricetagtype, pricetype tag pricetype, uomdimension tag uomdimension, istimelimited tag endtime ? true false, expirydate tag endtime, tiers tag pricetiers map(tier => ({ range `${tier startunit || 0} ${tier endunit || '∞'}`, chargemodel tier chargemodel, discount tier discountpercentage || 0, amount tier amount || 0 })) }; // categorize by type if (tag pricetagtype === 'quantity') { organizedtags volume push(taginfo); } else if (tag pricetagtype === 'term') { organizedtags term push(taginfo); } // check if it's promotional (time limited) if (tag endtime) { organizedtags promotional push(taginfo); } }); console log('price tag catalog ready for display ', organizedtags); return organizedtags; } catch (error) { console error('failed to load price tag catalog ', error); throw error; } } // usage buildpricetagcatalog() then(catalog => { // render your price tag catalog ui console log('\n📊 volume based price tags '); catalog volume foreach(tag => { console log(`🏷️ ${tag name} (${tag code})`); console log(` ${tag description}`); console log(` unit ${tag uomdimension}`); tag tiers foreach((tier, index) => { console log(` tier ${index + 1} ${tier range} units`); if (tier discount > 0) { console log(` discount ${tier discount}%`); } if (tier amount > 0) { console log(` price $${tier amount}`); } }); console log(''); }); console log('\n📅 term based price tags '); catalog term foreach(tag => { console log(`🏷️ ${tag name} (${tag code})`); console log(` ${tag description}`); tag tiers foreach((tier, index) => { console log(` tier ${index + 1} ${tier range}`); if (tier discount > 0) { console log(` discount ${tier discount}%`); } }); console log(''); }); if (catalog promotional length > 0) { console log('\n🎉 promotional price tags '); catalog promotional foreach(tag => { console log(`🏷️ ${tag name} (${tag code})`); console log(` ${tag description}`); console log(` expires ${tag expirydate}`); console log(''); }); } }); filtering and searching price tags for better user experience, you'll want to implement filtering and search function filterpricetags(pricetags, filters = {}) { return pricetags filter(tag => { // filter by active status if (filters activeonly && !tag active) return false; // note publishstatus will always be 'published' since only published tags are returned // no need to filter by publication status // filter by price tag type if (filters type && tag pricetagtype !== filters type) return false; // filter by code search if (filters code) { const searchterm = filters code tolowercase(); if (!tag code tolowercase() includes(searchterm)) return false; } // filter by name/description search if (filters search) { const searchterm = filters search tolowercase(); const matchesname = tag name tolowercase() includes(searchterm); const matchesdescription = tag description? tolowercase() includes(searchterm); if (!matchesname && !matchesdescription) return false; } // filter by time validity if (filters validnow) { const now = new date(); const starttime = tag starttime ? new date(tag starttime) new date('1970 01 01'); const endtime = tag endtime ? new date(tag endtime) new date('2099 12 31'); if (now < starttime || now > endtime) return false; } return true; }); } // usage example async function searchpricetags() { const alltags = await buildpricetagcatalog(); const flattags = \[ alltags volume, alltags term, alltags promotional]; // search for volume discounts currently valid const volumediscounts = filterpricetags(flattags, { type 'quantity', validnow true, activeonly true }); console log(`found ${volumediscounts length} active volume discounts`); // search for price tags by code const specifictag = filterpricetags(flattags, { code 'enterprise' }); console log(`found ${specifictag length} tags matching 'enterprise'`); } calculating price impact understanding how price tags affect final pricing is crucial for building quotes function calculatepriceimpact(baseprice, quantity, pricetag) { if (!pricetag || !pricetag tiers || pricetag tiers length === 0) { return { originalprice baseprice quantity, finalprice baseprice quantity, savings 0, effectivetier null }; } // find applicable tier based on quantity let applicabletier = null; for (const tier of pricetag tiers) { const tierstart = tier startunit || 0; const tierend = tier endunit || infinity; if (quantity >= tierstart && quantity <= tierend) { applicabletier = tier; break; } } if (!applicabletier) { return { originalprice baseprice quantity, finalprice baseprice quantity, savings 0, effectivetier null }; } let finalprice; const originalprice = baseprice quantity; if (pricetag pricetype === 'volume') { // volume pricing all units get the same rate if (applicabletier discountpercentage) { const discountmultiplier = 1 (applicabletier discountpercentage / 100); finalprice = originalprice discountmultiplier; } else if (applicabletier amount) { finalprice = applicabletier amount quantity; } else { finalprice = originalprice; } } else if (pricetag pricetype === 'tiered') { // tiered pricing different rates for different portions finalprice = 0; let remainingquantity = quantity; for (const tier of pricetag tiers sort((a, b) => a startunit b startunit)) { const tierstart = tier startunit || 0; const tierend = tier endunit || infinity; if (remainingquantity <= 0) break; const tierquantity = math min(remainingquantity, tierend tierstart); if (tier discountpercentage) { const discountmultiplier = 1 (tier discountpercentage / 100); finalprice += (baseprice tierquantity discountmultiplier); } else if (tier amount) { finalprice += (tier amount tierquantity); } else { finalprice += (baseprice tierquantity); } remainingquantity = tierquantity; } } return { originalprice originalprice, finalprice finalprice, savings originalprice finalprice, savingspercentage ((originalprice finalprice) / originalprice) 100, effectivetier applicabletier }; } // usage example async function demonstratepricing() { const pricetags = await buildpricetagcatalog(); const volumetag = pricetags volume\[0]; // get first volume discount if (volumetag) { const scenarios = \[ { quantity 5, baseprice 100 }, { quantity 25, baseprice 100 }, { quantity 100, baseprice 100 } ]; console log(`\n💰 pricing with ${volumetag name} `); scenarios foreach(scenario => { const pricing = calculatepriceimpact(scenario baseprice, scenario quantity, volumetag); console log(`\n📊 ${scenario quantity} units at $${scenario baseprice} base price `); console log(` original $${pricing originalprice tofixed(2)}`); console log(` final $${pricing finalprice tofixed(2)}`); console log(` savings $${pricing savings tofixed(2)} (${pricing savingspercentage tofixed(1)}%)`); if (pricing effectivetier) { console log(` applied tier ${pricing effectivetier range}`); } }); } } // run the demonstration demonstratepricing(); common patterns and best practices 1\ error handling always implement proper error handling for your price tag operations async function safepricetagfetch(pricetagcode = null) { try { const url = pricetagcode ? `https //api nue io/catalog/price tags/${pricetagcode}` 'https //api nue io/catalog/price tags'; const response = await fetch(url, { method 'get', headers myheaders }); if (!response ok) { throw new error(`http error! status ${response status}`); } const pricetags = await response json(); if (pricetagcode && pricetags length === 0) { throw new error(`price tag with code ${pricetagcode} not found or not published`); } return pricetags; } catch (error) { console error('price tag fetch error ', error); // return empty array for graceful degradation return \[]; } } 2\ caching price tags price tags don't change frequently, so implement caching class pricetagcache { constructor(ttlminutes = 60) { 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 getpricetags() { const cached = this get('all price tags'); if (cached) { console log('using cached price tag data'); return cached; } console log('fetching fresh price tag data'); const pricetags = await safepricetagfetch(); this set('all price tags', pricetags); return pricetags; } } // usage const pricetagcache = new pricetagcache(60); // 60 minute cache const pricetags = await pricetagcache getpricetags(); 3\ price tag validation validate price tags before applying them function validatepricetag(pricetag) { const now = new date(); // check if active if (!pricetag active) { return { valid false, reason 'price tag is not active' }; } // note publishstatus will always be 'published' since only published tags are returned by the api // no need to check publication status // check time validity if (pricetag starttime && new date(pricetag starttime) > now) { return { valid false, reason 'price tag has not started yet' }; } if (pricetag endtime && new date(pricetag endtime) < now) { return { valid false, reason 'price tag has expired' }; } return { valid true, reason 'price tag is valid' }; } next steps now that you understand basic price tag operations, you can learn about pricing strategies in the key considerations guide understand price tag types for implementing specific pricing models explore the data model to understand all available fields build dynamic pricing with real time price calculations move on to key considerations for price tags to learn about pricing strategies and implementation best practices, or price tag types to understand different pricing models you can implement