Guides and Examples
...
Orders
Activate Draft Orders
20 min
this guide provides comprehensive instructions for activating draft orders using the nue lifecycle management api learn how to convert draft orders into active orders, configure invoice generation, and implement efficient order activation workflows prerequisites before you begin, ensure you have a valid nue api key with order activation permissions draft order ids that are ready for activation understanding of invoice generation and activation options basic knowledge of rest apis and json familiarity with order lifecycle management authentication all order activation 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 order activation activate draft order with invoice generation try it now activate draft order ā https //api docs nue io/activate draft order const myheaders = new headers(); myheaders append("nue api key", "your api key here"); myheaders append("content type", "application/json"); // activate a draft order with invoice generation const draftorderid = "draft order 123e4567 e89b 12d3 a456 426614174000"; const activationdata = { options { generateinvoice true, // generate invoice during activation activateinvoice false // keep invoice as draft for manual review } }; fetch(`https //api nue io/orders/${draftorderid}`, { method 'post', headers myheaders, body json stringify(activationdata) }) then(response => response json()) then(result => { console log('order activated successfully ', result); if (result status === 'success') { const order = result data order; console log(`order id ${order id}`); console log(`order number ${order ordernumber}`); console log(`status ${order status}`); // should be "active" console log(`activation date ${order activateddate}`); // display created assets if (result data assets && result data assets length > 0) { console log(`\nš¦ assets created ${result data assets length}`); result data assets foreach(asset => { console log(` ${asset productname} ${asset quantity} units`); console log(` asset id ${asset id}`); console log(` status ${asset status}`); console log(` period ${asset startdate} to ${asset enddate}`); }); } // display invoice information if (result data invoices && result data invoices length > 0) { const invoice = result data invoices\[0]; console log(`\nš° invoice generated `); console log(`invoice id ${invoice id}`); console log(`amount $${invoice amount}`); console log(`status ${invoice status}`); // should be "draft" console log(`due date ${invoice duedate}`); } } }) catch(error => console log('error ', error)); activate order with immediate invoice activation activate both the order and generated invoice in one operation const immediateactivation = { options { generateinvoice true, activateinvoice true // immediately activate the generated invoice }, // optional add purchase order details ponumber "po 2025 67890", podate "2025 01 15" }; fetch(`https //api nue io/orders/${draftorderid}`, { method 'post', headers myheaders, body json stringify(immediateactivation) }) then(response => response json()) then(result => { if (result status === 'success') { const order = result data order; const invoice = result data invoices\[0]; console log('ā
order and invoice activated successfully'); console log(`order status ${order status}`); console log(`invoice status ${invoice status}`); // should be "posted" console log(`invoice balance $${invoice balance}`); console log(`payment due ${invoice duedate}`); // ready for customer billing console log('\nšÆ order fully activated and ready for billing'); } }) catch(error => console log('activation failed ', error)); advanced activation patterns order activation with external system integration integrate order activation with external payment/erp systems const externalsystemactivation = { options { generateinvoice true, activateinvoice true }, // purchase order information ponumber "po 2025 enterprise 001", podate "2025 01 10", // external system tracking transactionhub { externalsystem "stripe", // external payment system externalid "pi 1234567890abcdef", // external transaction id transactiontype "customer" // transaction type } }; fetch(`https //api nue io/orders/${draftorderid}`, { method 'post', headers myheaders, body json stringify(externalsystemactivation) }) then(response => response json()) then(result => { if (result status === 'success') { console log('ā
order activated with external system integration'); console log(`external system ${result data order transactionhub? externalsystem}`); console log(`external transaction id ${result data order transactionhub? externalid}`); // update external system with nue order details updateexternalsystem(result data order); } }) catch(error => console log('external integration activation failed ', error)); function updateexternalsystem(order) { // integrate with your external payment/erp system console log(`updating external system with order ${order ordernumber}`); // example update stripe subscription with nue order details const externalupdate = { nueorderid order id, nueordernumber order ordernumber, activationdate order activateddate, totalamount order grandtotal }; console log('external system update payload ', externalupdate); } bulk order activation service implement a service to activate multiple draft orders efficiently class orderactivationservice { constructor(apikey) { this apikey = apikey; this headers = new headers(); this headers append("nue api key", apikey); this headers append("content type", "application/json"); } async activateorder(draftorderid, activationoptions = {}) { try { // default activation configuration const defaultoptions = { generateinvoice true, activateinvoice false, // conservative default validatebeforeactivation true }; const options = { defaultoptions, activationoptions }; // step 1 validate order before activation (optional) if (options validatebeforeactivation) { await this validateorderforactivation(draftorderid); } // step 2 prepare activation payload const activationpayload = this prepareactivationpayload(options); // step 3 activate the order const result = await this submitactivation(draftorderid, activationpayload); // step 4 process activation result const processedresult = this processactivationresult(result); // step 5 handle post activation tasks await this handlepostactivation(processedresult); return { success true, order processedresult order, assets processedresult assets, invoices processedresult invoices, summary this generateactivationsummary(processedresult) }; } catch (error) { console error(`order activation failed for ${draftorderid} `, error); return { success false, error error message, draftorderid }; } } async validateorderforactivation(draftorderid) { // in a real implementation, you might fetch the draft order // and validate business rules before activation console log(`validating order ${draftorderid} for activation `); // example validations // check customer payment status // verify product availability // confirm pricing is current // validate subscription terms return true; } prepareactivationpayload(options) { const payload = { options { generateinvoice options generateinvoice, activateinvoice options activateinvoice } }; // add po information if provided if (options ponumber) { payload ponumber = options ponumber; } if (options podate) { payload podate = options podate; } // add external system integration if provided if (options transactionhub) { payload transactionhub = options transactionhub; } return payload; } async submitactivation(draftorderid, payload) { const response = await fetch(`https //api nue io/orders/${draftorderid}`, { method 'post', headers this headers, body json stringify(payload) }); if (!response ok) { const errortext = await response text(); throw new error(`activation failed ${response status} ${errortext}`); } const result = await response json(); if (result status !== 'success') { throw new error(`activation failed ${result message || 'unknown error'}`); } return result; } processactivationresult(apiresult) { return { order apiresult data order, assets apiresult data assets || \[], invoices apiresult data invoices || \[], entitlements apiresult data entitlements || \[] }; } async handlepostactivation(result) { const order = result order; // example post activation tasks // 1 send activation notifications await this sendactivationnotifications(order); // 2 update customer records await this updatecustomerrecords(order); // 3 provision services await this provisionservices(result assets); // 4 setup monitoring/tracking await this setupordertracking(order); } async sendactivationnotifications(order) { console log(`š§ sending activation notifications for order ${order ordernumber} `); // notify customer const customernotification = { to order customeremail, subject `order ${order ordernumber} activated`, template 'order activation', data { ordernumber order ordernumber, activationdate order activateddate, nextbillingdate order nextbillingdate } }; // notify internal teams const internalnotification = { to 'orders\@company com', subject `order activated ${order ordernumber}`, template 'internal order activation', data { ordernumber order ordernumber, customername order customername, totalvalue order grandtotal } }; console log('ā
activation notifications queued'); } async updatecustomerrecords(order) { console log(`š updating customer records for ${order customername} `); // update customer lifecycle stage // update account values // record activation event console log('ā
customer records updated'); } async provisionservices(assets) { console log(`š provisioning services for ${assets length} assets `); for (const asset of assets) { // provision each service/product console log(` provisioning ${asset productname} (${asset quantity} units)`); // integration points // create user accounts // setup service configurations // deploy infrastructure // configure access controls } console log('ā
service provisioning completed'); } async setupordertracking(order) { console log(`š setting up tracking for order ${order ordernumber} `); // setup monitoring and analytics const trackingdata = { orderid order id, ordernumber order ordernumber, activationdate order activateddate, customersegment order customersegment, ordervalue order grandtotal, subscriptionenddate order subscriptionenddate }; console log('ā
order tracking configured'); } generateactivationsummary(result) { const order = result order; const assets = result assets; const invoices = result invoices; return { orderid order id, ordernumber order ordernumber, customername order customername, activationdate order activateddate, status order status, totalassets assets length, activeassets assets filter(a => a status === 'active') length, totalinvoices invoices length, postedinvoices invoices filter(i => i status === 'posted') length, totalvalue order grandtotal, nextbillingdate order nextbillingdate }; } async activatemultipleorders(draftorderids, globaloptions = {}) { const results = \[]; const batchsize = 5; // process in batches to avoid rate limits console log(`š activating ${draftorderids length} orders in batches of ${batchsize} `); for (let i = 0; i < draftorderids length; i += batchsize) { const batch = draftorderids slice(i, i + batchsize); console log(`processing batch ${math floor(i/batchsize) + 1} `); const batchpromises = batch map(orderid => this activateorder(orderid, globaloptions) ); const batchresults = await promise allsettled(batchpromises); results push( batchresults); // brief pause between batches if (i + batchsize < draftorderids length) { await new promise(resolve => settimeout(resolve, 1000)); } } // analyze results const successful = results filter(r => r status === 'fulfilled' && r value success); const failed = results filter(r => r status === 'rejected' || !r value success); console log(`\nš bulk activation results `); console log(`ā
successful ${successful length}`); console log(`ā failed ${failed length}`); if (failed length > 0) { console log('\nā failed activations '); failed foreach(result => { const error = result status === 'rejected' ? result reason result value error; console log(` order ${result value? draftorderid || 'unknown'} ${error}`); }); } return { total draftorderids length, successful successful length, failed failed length, results results }; } } // usage examples const activationservice = new orderactivationservice("your api key here"); // single order activation const singleactivation = await activationservice activateorder( "draft order 123", { generateinvoice true, activateinvoice true, ponumber "po 2025 001", transactionhub { externalsystem "salesforce", externalid "006xx000004c0000", transactiontype "opportunity" } } ); if (singleactivation success) { console log(`ā
order ${singleactivation summary ordernumber} activated successfully`); console log(`assets created ${singleactivation summary totalassets}`); console log(`total value $${singleactivation summary totalvalue}`); } else { console error(`ā activation failed ${singleactivation error}`); } // bulk order activation const bulkorderids = \[ "draft order 123", "draft order 456", "draft order 789" ]; const bulkresult = await activationservice activatemultipleorders( bulkorderids, { generateinvoice true, activateinvoice false, // keep invoices as draft for review validatebeforeactivation true } ); console log(`bulk activation completed ${bulkresult successful}/${bulkresult total} orders activated`); order activation workflows approval based activation implement approval workflows for high value orders class approvalbasedactivationservice extends orderactivationservice { async activateorderwithapproval(draftorderid, options = {}) { try { // step 1 check if order requires approval const requiresapproval = await this checkapprovalrequirement(draftorderid); if (requiresapproval) { // step 2 submit for approval const approvalresult = await this submitforapproval(draftorderid); if (!approvalresult approved) { return { success false, requiresapproval true, approvalid approvalresult approvalid, message 'order submitted for approval' }; } } // step 3 proceed with activation return await this activateorder(draftorderid, options); } catch (error) { return { success false, error error message, draftorderid }; } } async checkapprovalrequirement(draftorderid) { // business logic to determine if approval is needed // examples // order value > $10,000 // custom pricing applied // non standard terms // new customer console log(`checking approval requirements for order ${draftorderid} `); // mock approval check const ordervalue = 15000; // would fetch actual order value return ordervalue > 10000; } async submitforapproval(draftorderid) { console log(`submitting order ${draftorderid} for approval `); // integration with approval system const approvalrequest = { orderid draftorderid, approvaltype 'order activation', submittedby 'api user', submitteddate new date() toisostring(), urgency 'normal' }; // mock approval submission return { approved false, // would be determined by approval system approvalid `approval ${date now()}`, estimatedapprovaltime '2 4 hours' }; } } request body schema required fields field type description example options object activation configuration options see options schema below options generateinvoice boolean whether to generate invoice during activation true options activateinvoice boolean whether to activate the generated invoice false optional fields field type description example ponumber string purchase order number "po 2025 67890" podate string purchase order date (yyyy mm dd) "2025 01 15" transactionhub object external system integration see transaction hub schema transaction hub schema field type description example externalsystem string external system identifier "stripe" , "salesforce" externalid string external transaction/record id "pi 1234567890abcdef" transactiontype string type of external transaction "customer" , "opportunity" response structure success response (201 created) { "status" "success", "data" { "order" { "id" "order uuid", "ordernumber" "ord 000001", "status" "active", "activateddate" "2025 01 15t10 30 00z", "customername" "customer name", "grandtotal" 9720 00, "nextbillingdate" "2025 02 15" }, "assets" \[ { "id" "asset uuid", "productname" "enterprise license", "status" "active", "quantity" 100, "startdate" "2025 01 15", "enddate" "2026 01 14" } ], "invoices" \[ { "id" "invoice uuid", "amount" 9720 00, "balance" 9720 00, "status" "posted", "duedate" "2025 02 14" } ], "entitlements" \[] } } error handling common activation errors error description resolution invalid draft order order not found or not in draft status verify order id and status invoice generation failed invoice creation failed check billing configuration asset provisioning failed asset creation failed review product configuration activation validation failed pre activation validation failed address validation issues robust error handling async function safeorderactivation(draftorderid, options) { try { const result = await activationservice activateorder(draftorderid, options); if (result success) { console log('ā
order activated successfully'); return result; } else { console error('ā activation failed ', result error); // handle specific error scenarios if (result error includes('invalid draft order')) { console log('š” check that order exists and is in draft status'); } else if (result error includes('invoice generation failed')) { console log('š” review customer billing configuration'); } return result; } } catch (error) { console error('unexpected activation error ', error); return { success false, error error message, draftorderid }; } } best practices activation strategy validate before activation to prevent failures use conservative invoice settings (generate but don't activate) for manual review implement approval workflows for high value orders track activation events for audit and analytics post activation tasks send customer notifications about service activation provision services immediately after activation update external systems with activation details monitor asset status and usage error recovery implement retry logic for transient failures provide clear error messages to users log activation attempts for troubleshooting have rollback procedures for failed activations this comprehensive guide enables you to efficiently activate draft orders using the nue lifecycle management api, supporting everything from simple activations to complex approval based workflows with external system integrations