Guides and Examples
...
Subscriptions
Retrieve Subscription Data for Client Side Pricing Engine
20 min
the nue self service api provides specialized endpoints for retrieving subscription data optimized for client side pricing calculations this enables real time pricing previews and calculations without server round trips overview client side pricing capabilities allow you to calculate subscription changes instantly preview pricing for quantity updates, renewals, and modifications provide immediate feedback show customers pricing impacts before submitting changes reduce server load perform calculations locally with cached pricing data improve user experience eliminate waiting times for pricing calculations key benefits real time calculations calculate prices instantly based on subscription changes without api calls during user interactions server side parity ensure consistent pricing logic between client and server calculations performance optimization reduce server load by offloading pricing calculations to the client offline capability enable pricing calculations even without active network connections api endpoint request format get /subscriptions/pricing engine input query parameters parameter type required description customerids array yes json encoded array of customer ids example request const customerid = "003xx000004tmfd"; const customerids = json stringify(\[customerid]); const url = `https //api nue io/subscriptions/pricing engine input?customerids=${encodeuricomponent(customerids)}`; const response = await fetch(url, { headers { 'authorization' 'bearer your api token', 'content type' 'application/json' } }); const pricingdata = await response json(); response structure the api returns subscription data organized by subscription name { "status" "success", "data" { "sub 00000483" { "changes" \[ { "changetype" "newproduct", "enddate" "2025 01 12", "linetype" "lineitem", "listtotal" 148 5, "netsalesprice" 9 9, "quantity" 15, "startdate" "2024 12 13", "subtotal" 148 5, "term" 1, "totalamount" 148 5, "totalprice" 148 5 } ], "orderproduct" { "enddate" "2025 01 12", "listprice" 9 9, "listtotal" 178 2, "product" { "id" "01tei0000088m9qiau", "name" "revenue dashboard", "pricemodel" "recurring", "productcategory" "recurringservices", "sku" "revenue dashboard" }, "quantity" 18, "startdate" "2024 12 13", "subtotal" 178 2, "term" 1 } } }, "warnings" \[] } using the pricing engine installation install the required packages npm install @nue apps/nue pricing clientjs npm install @nue apps/nue js implementation import { nuepricingchangeordercalculator } from '@nue apps/nue pricing clientjs'; // fetch pricing data async function getpricingenginedata(customerid) { const customerids = json stringify(\[customerid]); const url = `https //api nue io/subscriptions/pricing engine input?customerids=${encodeuricomponent(customerids)}`; const response = await fetch(url, { headers { 'authorization' 'bearer your api token', 'content type' 'application/json' } }); const result = await response json(); return result data; } // calculate subscription changes async function calculatesubscriptionchanges(subscription, changes) { const pricingdata = await getpricingenginedata(subscription customerid); const subscriptiondata = pricingdata\[subscription name]; if (!subscriptiondata) { throw new error(`no pricing data found for subscription ${subscription name}`); } const calculator = new nuepricingchangeordercalculator(); return calculator calculatewithassetchanges(subscriptiondata, changes); } common use cases quantity updates const quantitychanges = \[{ changetype 'updatequantity', newquantity 25, effectivedate '2024 07 01' }]; const result = await calculatesubscriptionchanges(subscription, quantitychanges); subscription renewals const renewalchanges = \[{ changetype 'renew', renewalterm 12 }]; const result = await calculatesubscriptionchanges(subscription, renewalchanges); term modifications const termchanges = \[{ changetype 'updateterm', newterm 24, effectivedate '2024 07 01' }]; const result = await calculatesubscriptionchanges(subscription, termchanges); best practices caching strategy implement intelligent caching to improve performance const pricingcache = new map(); const cache ttl = 5 60 1000; // 5 minutes async function getcachedpricingdata(customerid) { const cachekey = customerid; const cached = pricingcache get(cachekey); if (cached && date now() cached timestamp < cache ttl) { return cached data; } const data = await getpricingenginedata(customerid); pricingcache set(cachekey, { data, timestamp date now() }); return data; } error handling async function safecalculatechanges(subscription, changes) { try { return await calculatesubscriptionchanges(subscription, changes); } catch (error) { console error('pricing calculation failed ', error); if (error message includes('no pricing data found')) { return { error 'pricing data unavailable' }; } throw error; } } batch processing process multiple calculations efficiently async function batchcalculatesubscriptions(subscriptionchanges) { const customerids = \[ new set( subscriptionchanges map(item => item subscription customerid) )]; // fetch all pricing data at once const allpricingdata = await promise all( customerids map(id => getpricingenginedata(id)) ); // process calculations return promise all( subscriptionchanges map(({ subscription, changes }) => { const pricingdata = allpricingdata find(data => data\[subscription name] ); if (pricingdata) { return calculatesubscriptionchanges(subscription, changes); } return null; }) ); } response format pricing calculations return detailed pricing information { "assetprice" { "assetnumber" "sub 000084", "changeitems" \[ { "deltaacv" 50000, "deltaarr" 50000, "deltacmrr" 4166 67, "deltatcv" 600000, "changetype" "renew", "totalamount" 660000, "totalprice" 600000 } ], "enddate" "2046 03 03", "quantity" 100, "startdate" "2022 03 04", "term" 24 }, "pricesummary" { "totalamount" 660000, "totalprice" 600000 } } related resources for additional information on subscription management and pricing subscription management guide overview of subscription operations advanced subscription workflows complex subscription scenarios client side pricing engine documentation complete technical reference this specialized endpoint provides the foundation for building responsive, real time pricing experiences in your subscription management applications