Guides and Examples
...
Contacts
Updating Contact
25 min
this guide provides comprehensive instructions for updating existing contacts using the nue lifecycle management api learn how to modify contact information, update professional details, and implement efficient contact management workflows prerequisites before you begin, ensure you have a valid nue api key with contact update permissions valid contact id (uuid) understanding of contact data structures basic knowledge of rest apis and json authentication all contact update 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 contact updates update basic information try it now update contact ā https //api docs nue io/update contact const myheaders = new headers(); myheaders append("nue api key", "your api key here"); myheaders append("content type", "application/json"); // update basic contact information const contactid = "contact uuid 12345"; const updatedata = { firstname "jane", // updated first name lastname "smith johnson", // updated last name (married) name "jane smith johnson", // updated full name email "jane smith johnson\@acme com", // new email title "senior software engineer", // promotion phone "+1 555 0199" // updated phone number }; fetch(`https //api nue io/contacts/${contactid}`, { method 'patch', headers myheaders, body json stringify(updatedata) }) then(response => response json()) then(result => { if (result status === 'success') { const contact = result data\[0]; console log('contact updated successfully ', result); console log(`updated ${contact name}`); console log(`email ${contact email}`); console log(`title ${contact title}`); console log(`phone ${contact phone}`); console log(`last modified ${contact lastmodifieddate}`); // handle any warnings if (result warnings && result warnings length > 0) { console warn('warnings ', result warnings); } } else { console error('failed to update contact ', result error); } }) catch(error => console log('error ', error)); update professional information modify title, role, and work related details const contactid = "contact uuid 12345"; const professionalupdatedata = { title "vp of engineering", // promoted phone "+1 555 0200", // new direct line mobilephone "+1 555 0300", // added mobile // updated business address billingstreet "456 corporate center, suite 1200", billingcity "new york", billingstate "ny", billingpostalcode "10001", billingcountry "united states" }; fetch(`https //api nue io/contacts/${contactid}`, { method 'patch', headers myheaders, body json stringify(professionalupdatedata) }) then(response => response json()) then(result => { if (result status === 'success') { const contact = result data\[0]; console log('ā
professional information updated '); console log(`name ${contact name}`); console log(`new title ${contact title}`); console log(`phone ${contact phone}`); console log(`mobile ${contact mobilephone}`); console log(`business address ${contact billingstreet}, ${contact billingcity}, ${contact billingstate}`); // handle any warnings if (result warnings && result warnings length > 0) { console warn('warnings ', result warnings); } } else { console error('failed to update professional information ', result error); } }) catch(error => console log('error ', error)); update personal information modify personal details and home address const contactid = "contact uuid 12345"; const personalupdatedata = { middlename "marie", // added middle name suffix "phd", // added suffix for degree birthday "1985 07 15", // corrected birthday mobilephone "+1 555 0350", // updated mobile number // updated home/shipping address shippingstreet "789 residential lane", shippingcity "brooklyn", shippingstate "ny", shippingpostalcode "11201", shippingcountry "united states" }; fetch(`https //api nue io/contacts/${contactid}`, { method 'patch', headers myheaders, body json stringify(personalupdatedata) }) then(response => response json()) then(result => { if (result status === 'success') { const contact = result data\[0]; console log('ā
personal information updated '); console log(`full name ${contact firstname} ${contact middlename} ${contact lastname} ${contact suffix}`); console log(`birthday ${contact birthday}`); console log(`mobile ${contact mobilephone}`); console log(`home address ${contact shippingstreet}, ${contact shippingcity}, ${contact shippingstate}`); // handle any warnings if (result warnings && result warnings length > 0) { console warn('warnings ', result warnings); } } else { console error('failed to update personal information ', result error); } }) catch(error => console log('error ', error)); advanced contact update patterns contact lifecycle management handle contact role changes and career progression class contactlifecyclemanager { constructor(apikey) { this apikey = apikey; this headers = new headers(); this headers append("nue api key", apikey); this headers append("content type", "application/json"); } async promotecontact(contactid, promotiondata) { try { console log(`š promoting contact ${contactid} `); // prepare promotion update const promotionupdate = { title promotiondata newtitle, // update contact methods for new role phone promotiondata newphone || undefined, mobilephone promotiondata newmobile || undefined, // update address if new office location (promotiondata newaddress && { billingstreet promotiondata newaddress street, billingcity promotiondata newaddress city, billingstate promotiondata newaddress state, billingpostalcode promotiondata newaddress postalcode, billingcountry promotiondata newaddress country }) }; const response = await fetch(`https //api nue io/contacts/${contactid}`, { method 'patch', headers this headers, body json stringify(promotionupdate) }); if (!response ok) { throw new error(`promotion failed ${response status} ${response statustext}`); } const updatedcontact = await response json(); console log('ā
promotion completed '); console log(` contact ${updatedcontact name}`); console log(` previous title ${promotiondata previoustitle || 'unknown'}`); console log(` new title ${updatedcontact title}`); console log(` effective date ${new date() toisostring() split('t')\[0]}`); // log promotion for audit trail await this logcontactchange(contactid, 'promotion', { from promotiondata previoustitle, to updatedcontact title, date new date() toisostring() }); return updatedcontact; } catch (error) { console error('ā contact promotion failed ', error); throw error; } } async updatecontactlocation(contactid, relocationdata) { try { console log(`š relocating contact ${contactid} `); const relocationupdate = { // update business address billingstreet relocationdata newoffice street, billingcity relocationdata newoffice city, billingstate relocationdata newoffice state, billingpostalcode relocationdata newoffice postalcode, billingcountry relocationdata newoffice country, // update personal address if provided (relocationdata newhome && { shippingstreet relocationdata newhome street, shippingcity relocationdata newhome city, shippingstate relocationdata newhome state, shippingpostalcode relocationdata newhome postalcode, shippingcountry relocationdata newhome country }), // update phone numbers if they changed due to location (relocationdata newphone && { phone relocationdata newphone }), (relocationdata newmobile && { mobilephone relocationdata newmobile }) }; const response = await fetch(`https //api nue io/contacts/${contactid}`, { method 'patch', headers this headers, body json stringify(relocationupdate) }); if (!response ok) { throw new error(`relocation failed ${response status}`); } const contact = await response json(); console log('ā
contact relocation completed '); console log(` contact ${contact name}`); console log(` new office ${contact billingcity}, ${contact billingstate}`); if (contact shippingcity) { console log(` new home ${contact shippingcity}, ${contact shippingstate}`); } return contact; } catch (error) { console error('ā contact relocation failed ', error); throw error; } } async updatecontactdetails(contactid, personalchanges) { try { console log(`š¤ updating personal details for contact ${contactid} `); // handle name changes (marriage, legal name change, etc ) const nameupdate = {}; if (personalchanges namechange) { nameupdate firstname = personalchanges namechange firstname || undefined; nameupdate lastname = personalchanges namechange lastname || undefined; nameupdate middlename = personalchanges namechange middlename || undefined; nameupdate suffix = personalchanges namechange suffix || undefined; // reconstruct full name const nameparts = \[ personalchanges namechange firstname, personalchanges namechange middlename, personalchanges namechange lastname, personalchanges namechange suffix ] filter(boolean); nameupdate name = nameparts join(' '); } const personalupdate = { nameupdate, (personalchanges newemail && { email personalchanges newemail }), (personalchanges newbirthday && { birthday personalchanges newbirthday }), (personalchanges newmobile && { mobilephone personalchanges newmobile }) }; const response = await fetch(`https //api nue io/contacts/${contactid}`, { method 'patch', headers this headers, body json stringify(personalupdate) }); if (!response ok) { throw new error(`personal update failed ${response status}`); } const contact = await response json(); console log('ā
personal details updated '); console log(` name ${contact name}`); console log(` email ${contact email}`); if (contact birthday) { console log(` birthday ${contact birthday}`); } return contact; } catch (error) { console error('ā personal details update failed ', error); throw error; } } async logcontactchange(contactid, changetype, changedata) { // in a real implementation, this would log to an audit system console log(`š logging ${changetype} for contact ${contactid} `, changedata); } } // usage examples const lifecyclemanager = new contactlifecyclemanager("your api key here"); // promote contact lifecyclemanager promotecontact( "contact uuid 12345", { previoustitle "senior software engineer", newtitle "engineering manager", newphone "+1 555 0400", newaddress { street "100 executive plaza, suite 2000", city "san francisco", state "ca", postalcode "94105", country "united states" } } ) then(contact => { console log('promotion completed successfully'); }); // relocate contact lifecyclemanager updatecontactlocation( "contact uuid 12345", { newoffice { street "200 tech park drive", city "austin", state "tx", postalcode "73301", country "united states" }, newhome { street "456 residential circle", city "austin", state "tx", postalcode "73344", country "united states" }, newmobile "+1 512 555 0200" } ) then(contact => { console log('relocation completed successfully'); }); // update personal details (marriage, name change) lifecyclemanager updatecontactdetails( "contact uuid 12345", { namechange { firstname "jane", lastname "smith johnson", // married name middlename "marie" }, newemail "jane smith johnson\@newemail com", newmobile "+1 555 0555" } ) then(contact => { console log('personal details updated successfully'); }); bulk contact updates efficiently update multiple contacts with similar changes class bulkcontactupdater { constructor(apikey) { this apikey = apikey; this headers = new headers(); this headers append("nue api key", apikey); this headers append("content type", "application/json"); } async updatemultiplecontacts(contactupdates, options = {}) { const results = { successful \[], failed \[], total contactupdates length }; console log(`š starting bulk update of ${contactupdates length} contacts `); // process updates with controlled concurrency const concurrency = options concurrency || 5; for (let i = 0; i < contactupdates length; i += concurrency) { const batch = contactupdates slice(i, i + concurrency); const batchpromises = batch map(update => this updatesinglecontact(update contactid, update data) then(contact => ({ contactid update contactid, contact, success true })) catch(error => ({ contactid update contactid, error error message, success false })) ); const batchresults = await promise all(batchpromises); batchresults foreach(result => { if (result success) { results successful push(result); console log(`ā
updated ${result contact name}`); } else { results failed push(result); console log(`ā failed ${result contactid} ${result error}`); } }); // add delay between batches to respect rate limits if (i + concurrency < contactupdates length) { await this delay(1000); // 1 second delay } } console log(`\nš bulk update completed `); console log(` successful ${results successful length}`); console log(` failed ${results failed length}`); console log(` total ${results total}`); return results; } async updatesinglecontact(contactid, updatedata) { const response = await fetch(`https //api nue io/contacts/${contactid}`, { method 'patch', headers this headers, body json stringify(updatedata) }); if (!response ok) { throw new error(`http ${response status} ${response statustext}`); } const result = await response json(); if (result status === 'success') { return result data\[0]; } else { throw new error(`contact update failed ${result error}`); } } delay(ms) { return new promise(resolve => settimeout(resolve, ms)); } } // usage example update office address for multiple contacts const bulkupdater = new bulkcontactupdater("your api key here"); const contactupdates = \[ { contactid "contact 1 id", data { billingstreet "new corporate campus, building a", billingcity "seattle", billingstate "wa", billingpostalcode "98101" } }, { contactid "contact 2 id", data { billingstreet "new corporate campus, building a", billingcity "seattle", billingstate "wa", billingpostalcode "98101" } }, { contactid "contact 3 id", data { billingstreet "new corporate campus, building a", billingcity "seattle", billingstate "wa", billingpostalcode "98101" } } ]; bulkupdater updatemultiplecontacts(contactupdates, { concurrency 3 }) then(results => { console log('bulk update process completed'); if (results failed length > 0) { console log('failed updates need attention ', results failed); } }); contact data synchronization keep contact information synchronized across systems class contactsyncmanager { constructor(apikey) { this apikey = apikey; this headers = new headers(); this headers append("nue api key", apikey); this headers append("content type", "application/json"); } async synccontactfromexternalsystem(contactid, externalcontactdata) { try { console log(`š syncing contact ${contactid} from external system `); // map external data to nue contact format const syncupdate = this mapexternaltonueformat(externalcontactdata); // validate changes before applying const currentcontact = await this getcurrentcontact(contactid); const changeset = this detectchanges(currentcontact, syncupdate); if (object keys(changeset) length === 0) { console log('ā
contact is already in sync no changes needed'); return currentcontact; } console log(`š detected changes `, object keys(changeset)); // apply changes const response = await fetch(`https //api nue io/contacts/${contactid}`, { method 'patch', headers this headers, body json stringify(changeset) }); if (!response ok) { throw new error(`sync failed ${response status}`); } const updatedcontact = await response json(); console log('ā
contact synchronized successfully'); console log(` contact ${updatedcontact name}`); console log(` updated fields ${object keys(changeset) join(', ')}`); return updatedcontact; } catch (error) { console error('ā contact sync failed ', error); throw error; } } async getcurrentcontact(contactid) { // in practice, you might fetch the current contact to compare // for this example, we'll simulate it return { id contactid, name "current name", email "current\@email com", title "current title" }; } mapexternaltonueformat(externaldata) { // map external system fields to nue contact fields return { firstname externaldata first name, lastname externaldata last name, name `${externaldata first name} ${externaldata last name}`, email externaldata email address, title externaldata job title, phone externaldata work phone, mobilephone externaldata mobile phone, billingstreet externaldata office address? street, billingcity externaldata office address? city, billingstate externaldata office address? state, billingpostalcode externaldata office address? zip code, billingcountry externaldata office address? country }; } detectchanges(current, updated) { const changes = {}; object keys(updated) foreach(key => { if (updated\[key] !== undefined && current\[key] !== updated\[key]) { changes\[key] = updated\[key]; } }); return changes; } } // usage const syncmanager = new contactsyncmanager("your api key here"); const externalcontactdata = { first name "john", last name "smith", email address "john smith\@updated com", job title "senior director", work phone "+1 555 0600", mobile phone "+1 555 0700", office address { street "300 innovation drive", city "boston", state "ma", zip code "02101", country "united states" } }; syncmanager synccontactfromexternalsystem("contact uuid 12345", externalcontactdata) then(contact => { console log('contact sync completed successfully'); }); error handling and validation robust contact update implementation async function safecontactupdate(contactid, updatedata, options = {}) { const myheaders = new headers(); myheaders append("nue api key", "your api key here"); myheaders append("content type", "application/json"); try { // validate contact id if (!contactid || typeof contactid !== 'string') { throw new error('valid contact id is required'); } // validate update data if (!updatedata || typeof updatedata !== 'object') { throw new error('update data is required and must be an object'); } // remove read only fields if present const sanitizeddata = { updatedata }; delete sanitizeddata id; delete sanitizeddata customerid; delete sanitizeddata createddate; delete sanitizeddata createdbyid; delete sanitizeddata lastmodifieddate; delete sanitizeddata lastmodifiedbyid; // validate specific fields if (sanitizeddata email && !isvalidemail(sanitizeddata email)) { throw new error('invalid email format'); } if (sanitizeddata phone && !isvalidphone(sanitizeddata phone)) { throw new error('invalid phone number format'); } if (sanitizeddata mobilephone && !isvalidphone(sanitizeddata mobilephone)) { throw new error('invalid mobile phone number format'); } if (sanitizeddata birthday && !isvaliddate(sanitizeddata birthday)) { throw new error('invalid birthday format, use yyyy mm dd'); } // validate field lengths if (sanitizeddata firstname && sanitizeddata firstname length > 40) { throw new error('firstname cannot exceed 40 characters'); } if (sanitizeddata lastname && sanitizeddata lastname length > 80) { throw new error('lastname cannot exceed 80 characters'); } if (sanitizeddata name && sanitizeddata name length > 255) { throw new error('name cannot exceed 255 characters'); } // perform update const response = await fetch(`https //api nue io/contacts/${contactid}`, { method 'patch', headers myheaders, body json stringify(sanitizeddata) }); if (!response ok) { const errortext = await response text(); throw new error(`update failed ${response status} ${errortext}`); } const updatedcontact = await response json(); // log successful update if (options verbose) { console log(`ā
contact ${updatedcontact name} updated successfully`); console log(` last modified ${updatedcontact lastmodifieddate}`); } return { success true, contact updatedcontact, contactid contactid }; } catch (error) { console error(`ā failed to update contact ${contactid} `, error message); return { success false, error error message, contactid contactid }; } } function isvalidemail(email) { const emailregex = /^\[^\s@]+@\[^\s@]+\\ \[^\s@]+$/; return emailregex test(email); } function isvalidphone(phone) { const phoneregex = /^\\+?\[\d\s\\ \\(\\)]{10,}$/; return phoneregex test(phone); } function isvaliddate(datestring) { const dateregex = /^\d{4} \d{2} \d{2}$/; if (!dateregex test(datestring)) return false; const date = new date(datestring); return date instanceof date && !isnan(date) && date toisostring() split('t')\[0] === datestring; } // usage with error handling safecontactupdate( "contact uuid 12345", { email "updated\@email com", title "senior manager", phone "+1 555 0199", mobilephone "+1 555 0299" }, { verbose true } ) then(result => { if (result success) { console log('update completed ', result contact name); } else { console log('update failed, implement retry or escalation logic'); } }); updatable fields reference personal information firstname first name (max 40 chars) lastname last name (max 80 chars) middlename middle name (max 40 chars) suffix name suffix (max 40 chars) name full name (max 255 chars) birthday birth date (yyyy mm dd format) contact information email email address phone primary phone number mobilephone mobile phone number professional information title professional title address information billing billingstreet , billingcity , billingstate , billingpostalcode , billingcountry shipping shippingstreet , shippingcity , shippingstate , shippingpostalcode , shippingcountry common update scenarios name change (marriage/legal) // marriage or legal name change const namechange = { firstname "jane", lastname "smith johnson", name "jane smith johnson", email "jane smith johnson\@email com" }; job promotion // career advancement const promotion = { title "senior director of engineering", phone "+1 555 0400" // new direct line }; office relocation // company moved offices const relocation = { billingstreet "new office building", billingcity "new city", billingstate "ny", phone "+1 555 0500" }; contact method updates // new phone numbers or email const contactupdate = { email "new\ email\@company com", mobilephone "+1 555 0600" }; best practices update strategy validate data before sending updates use partial updates only send changed fields implement retry logic for transient failures log all updates for audit trails handle concurrent updates appropriately performance batch related updates when possible respect rate limits (1000 requests/minute) use controlled concurrency for bulk operations implement proper error handling and recovery data integrity validate business rules before updates maintain data consistency across related records handle dependent data appropriately (e g , email changes affecting logins) implement proper versioning for audit trails communication notify stakeholders of important changes (role changes, contact info) update external systems when contact information changes maintain communication preferences and opt out lists document change reasons for compliance this comprehensive guide enables you to efficiently update contact information using the nue lifecycle management api, supporting everything from simple field updates to complex lifecycle management and synchronization workflows