Guides and Examples
...
Assets
Fetching Assets
12 min
retrieve asset data using the nue lifecycle management api assets represent physical or tangible items created when orders are activated, tracking deployment and utilization throughout their lifecycle prerequisites before you begin, ensure you have a valid nue api key with asset read permissions customer ids or asset numbers for the assets you want to retrieve basic understanding of rest apis and json familiarity with asset lifecycle and status management authentication all asset retrieval 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"); basic asset retrieval fetch all assets for customer try it now fetch assets → https //api docs nue io/fetch assets const myheaders = new headers(); myheaders append("nue api key", "your api key here"); myheaders append("content type", "application/json"); // fetch all assets for a customer const customerids = \["d2e04653 ae90 49df a986 134cf64f6d03"]; const encodedcustomerids = encodeuricomponent(json stringify(customerids)); fetch(`https //api nue io/assets?customerids=${encodedcustomerids}`, { method 'get', headers myheaders }) then(response => response json()) then(result => { if (result status === 'success' && result data) { console log(`found ${result data length} assets`); result data foreach(asset => { console log(`${asset assetnumber} ${asset status} ${asset quantity} units`); console log(`product ${asset productid}, price $${asset price || 0}`); }); } }) catch(error => console log('error ', error)); filtered asset retrieval fetch assets by status const customerids = \["d2e04653 ae90 49df a986 134cf64f6d03"]; const encodedcustomerids = encodeuricomponent(json stringify(customerids)); // fetch only active assets fetch(`https //api nue io/assets?customerids=${encodedcustomerids}\&status=active`, { method 'get', headers myheaders }) then(response => response json()) then(result => { if (result status === 'success' && result data) { result data foreach(asset => { console log(`${asset assetnumber} ${asset status}`); console log(`product ${asset productid}, quantity ${asset quantity}`); }); } }) catch(error => console log('error ', error)); fetch specific asset by asset number const assetnumber = "ast 001234"; fetch(`https //api nue io/assets?assetnumber=${encodeuricomponent(assetnumber)}`, { method 'get', headers myheaders }) then(response => response json()) then(result => { if (result status === 'success' && result data length > 0) { const asset = result data\[0]; console log(`asset ${asset assetnumber}`); console log(`status ${asset status}, product ${asset productid}`); console log(`quantity ${asset quantity}, price $${asset price}`); } }) catch(error => console log('error ', error)); including related data fetch assets with product details const customerids = \["d2e04653 ae90 49df a986 134cf64f6d03"]; const encodedids = encodeuricomponent(json stringify(customerids)); // include product details in the response fetch(`https //api nue io/assets?customerids=${encodedids}\&includes=product`, { method 'get', headers myheaders }) then(response => response json()) then(result => { if (result status === 'success' && result data) { result data foreach(asset => { console log(`asset ${asset assetnumber}`); console log(`status ${asset status}, quantity ${asset quantity}`); if (asset product) { console log(`product ${asset product name} (${asset product sku})`); } }); } }) catch(error => console log('error ', error)); asset history and version tracking async function fetchassethistory(assetnumber) { const response = await fetch( `https //api nue io/assets?assetnumber=${encodeuricomponent(assetnumber)}\&history=true`, { method 'get', headers myheaders } ); const result = await response json(); if (result status === 'success' && result data length > 0) { console log(`asset history for ${assetnumber} `); result data foreach(version => { console log(`version ${version assetversion} ${version status}`); console log(`quantity ${version quantity}, price $${version price || 0}`); }); return result data; } return \[]; } // usage fetchassethistory("ast 001234"); query parameters reference parameter type required description customerids array\[string] json encoded array of customer ids assetnumber string specific asset number to fetch status string no filter by asset status includes string no related data to include either customerids or assetnumber is required response structure success response (200 ok) { "status" "success", "data" \[ { "id" "asset uuid", "assetnumber" "ast 001234", "name" "enterprise software license", "status" "active", "customerid" "customer uuid", "productid" "product uuid", "orderproductid" "order product uuid", "quantity" 5, "installdate" "2024 01 15", "purchasedate" "2024 01 10", "price" 2500 00, "assetversion" 1, "billingaccountid" "billing account uuid", "createddate" "2024 01 10t10 00 00z", "lastmodifieddate" "2024 01 15t14 30 00z", "product" { "id" "product uuid", "name" "enterprise software", "sku" "esw 001", "description" "enterprise software license" } } ], "warnings" \[] } error handling async function safeassetfetch(customerids, options = {}) { try { if (!array isarray(customerids) || customerids length === 0) { throw new error('customerids must be a non empty array'); } const encodedids = encodeuricomponent(json stringify(customerids)); let url = `https //api nue io/assets?customerids=${encodedids}`; if (options status) url += `\&status=${options status}`; if (options includes) url += `\&includes=${options includes}`; const response = await fetch(url, { method 'get', headers myheaders }); if (!response ok) { throw new error(`http ${response status} ${response statustext}`); } const result = await response json(); if (result status !== 'success') { throw new error(`api error ${result message || 'unknown error'}`); } return { assets result data || \[], found result data? length || 0, warnings result warnings || \[] }; } catch (error) { console error('asset fetch error ', error); return { assets \[], found 0, error error message }; } }