Guides and Examples
...
Lifecycle Manager
Customers
Getting Started with Customer Management
14 min
this guide walks you through the essential customer management operations in the nue self service api you'll learn how to create, retrieve, and update customers with practical examples prerequisites before you begin, ensure you have a valid nue api key access to the nue lifecycle manager api please make sure you understand json and restful api's authentication all customer 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"); creating your first customer let's start with creating a basic customer record this is typically the first step in any customer onboarding flow basic customer creation try it now create customers api → https //api docs nue io/create customers const myheaders = new headers(); myheaders append("nue api key", "your api key here"); myheaders append("content type", "application/json"); // create a basic customer record const customerdata = json stringify(\[ { "name" "digital innovations llc", "recordtype" "business", "email" "contact\@digitalinnovations com", "phone" "+1 555 0100", "billingstreet" "123 tech avenue", "billingcity" "san francisco", "billingstate" "ca", "billingpostalcode" "94105", "billingcountry" "united states" } ]); const requestoptions = { method 'post', headers myheaders, body customerdata, redirect 'follow' }; fetch("https //api nue io/customers", requestoptions) then(response => response json()) then(result => { console log('customer created successfully ', result); // save the customer id for future operations const customerid = result data\[0] id; localstorage setitem('customerid', customerid); }) catch(error => console log('error', error)); required vs optional fields when creating a customer, only two fields are absolutely required name (required) the customer's display name recordtype (required) either "business" or "consumer" however, for practical implementations, you'll typically want to include billing address fields required for payment processing shipping address fields required for tax calculations retrieving customer information once you have customers in your system, you'll need to retrieve their information for various operations basic customer retrieval try it now fetch customers api → https //api docs nue io/fetch customers const myheaders = new headers(); myheaders append("nue api key", "your api key here"); myheaders append("content type", "application/json"); // retrieve specific customers by id const customerids = \['cust digital 001']; const encodedids = encodeuricomponent(json stringify(customerids)); const requestoptions = { method 'get', headers myheaders, redirect 'follow' }; fetch(`https //api nue io/customers?customerids=${encodedids}`, requestoptions) then(response => response json()) then(result => { console log('customer information ', result); // display customer details result data foreach(customer => { console log(`customer ${customer name}`); console log(`email ${customer email}`); console log(`arr $${customer todayarr || 0}`); }); }) catch(error => console log('error', error)); including contact information you can also retrieve customers with their associated contacts in a single call try it now fetch customers api → https //api docs nue io/fetch customers const myheaders = new headers(); myheaders append("nue api key", "your api key here"); myheaders append("content type", "application/json"); // retrieve customer with contacts in one call const customerids = \['cust digital 001']; const encodedids = encodeuricomponent(json stringify(customerids)); const requestoptions = { method 'get', headers myheaders, redirect 'follow' }; fetch(`https //api nue io/customers?customerids=${encodedids}\&includes=contacts`, requestoptions) then(response => response json()) then(result => { console log('customer with contacts ', result); result data foreach(customer => { console log(`customer ${customer name}`); // display contacts if available if (customer contacts && customer contacts length > 0) { console log('contacts '); customer contacts foreach(contact => { console log(` ${contact firstname} ${contact lastname} (${contact email})`); }); } else { console log('no contacts found'); } }); }) catch(error => console log('error', error)); updating customer information as customer information changes, you'll need to update their records use the patch endpoint to modify specific fields while preserving others basic customer update try it now update customer api → https //api docs nue io/update customer const myheaders = new headers(); myheaders append("nue api key", "your api key here"); myheaders append("content type", "application/json"); // update customer contact information const updatedata = json stringify({ "email" "newemail\@digitalinnovations com", "phone" "+1 555 0199", "website" "https //digitalinnovations com" }); const customerid = 'cust digital 001'; const requestoptions = { method 'patch', headers myheaders, body updatedata, redirect 'follow' }; fetch(`https //api nue io/customers/${customerid}`, requestoptions) then(response => response json()) then(result => { console log('customer updated ', result); }) catch(error => console log('error', error)); common patterns and best practices 1\ error handling always implement proper error handling for your customer operations fetch(apiurl, requestoptions) then(response => { if (!response ok) { throw new error(`http error! status ${response status}`); } return response json(); }) then(result => { // handle success }) catch(error => { console error('api error ', error); // handle error appropriately }); 2\ data validation before sending requests, validate required fields function validatecustomer(customer) { if (!customer name || !customer recordtype) { throw new error('name and recordtype are required'); } if (!\['business', 'consumer'] includes(customer recordtype)) { throw new error('recordtype must be business or consumer'); } return true; } 3\ storing customer ids always store the customer id returned from creation for future operations // after successful customer creation const customerid = result data\[0] id; localstorage setitem('currentcustomerid', customerid); // later retrieval const storedcustomerid = localstorage getitem('currentcustomerid'); next steps now that you understand basic customer management, you can add contacts to your customers using the contacts api create orders for your customers to start the sales process explore advanced workflows for complex business scenarios learn about customer data validation and all available fields move on to advanced customer workflows to learn about complex scenarios like bulk operations, integration monitoring, and sophisticated onboarding flows