> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # Method name: updateContact(contactId: string, info: ContactInfo, revision: number, options: UpdateContactOptions) # Method package: wixCrmV2 # Method menu location: wixCrmV2 --> contacts --> updateContact # Method Link: https://dev.wix.com/docs/velo/apis/wix-crm-v2/contacts/contacts/update-contact.md # Method Description: Updates a contact. Each time the contact is updated, `revision` increments by 1. The existing `revision` must be included when updating the contact. This ensures you're working with the latest contact information, and it prevents unintended overwrites. You can't call Update Contact to update the `primaryEmail` of a contact who is also a member. Instead, use the Members API to update the member's login email, which will also update the contact's primary email. Members are typically linked to contacts, and while they share a relationship, the member ID and contact ID are distinct identifiers. Make sure to specifiy the contact ID when calling Update Contact. # Method Code Examples: *** Note: do not assume any prop names or enum values other than the ones in the example. ## Update a contact by adding a phone number (dashboard page code) ```javascript import { contacts } from 'wix-crm.v2'; /* Sample contactId value: '2712ae1d-3f64-46c2-ac3a-94a6c2e29847' * * Sample revision value: '5' * * Sample info object: * { * phones: { * items: [ * { * countryCode:"US", * phone:"6465676359", * primary:true, * tag:"MOBILE" * }, * { * phone: "2421642341", * countryCode: "US", * primary: false, * tag: "HOME" * } * ] * } * } */ export async function myUpdateContactFunction(contactId, info, revision, options) { try { const updatedContact = await contacts.updateContact(contactId, info, revision, options); console.log('Successfully updated contact:', updatedContact) return updatedContact; } catch (error) { console.log(error); // Handle the error } } /* Promise resolves to: * { * "contact": { * "revision": 17, * "source": { * "sourceType": "WIX_CODE", * "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a" * }, * "lastActivity": { * "activityDate": "2023-12-24T11:50:46.048Z", * "activityType": "CONTACT_CREATED" * }, * "primaryInfo": { * "email": "johndoe1@example.com", * "phone": "646-567-6359" * }, * "info": { * "name": { * "first": "John", * "last": "Doe" * }, * "emails": { * "items": [ * { * "tag": "UNTAGGED", * "email": "johndoe1@example.com", * "primary": true, * "_id": "37db3bde-83c0-4ca2-8097-88964a2f343b" * }, * { * "tag": "UNTAGGED", * "email": "john.doe.at.home@example.com", * "primary": false, * "_id": "06eef938-13d2-49f3-8097-60686ab4ddd2" * } * ] * }, * "phones": { * "items": [ * { * "tag": "MOBILE", * "countryCode": "US", * "phone": "646-567-6359", * "e164Phone": "+16465676359", * "primary": true, * "_id": "01e597c0-76c6-4791-bb77-8b3309f893d1" * }, * { * "tag": "HOME", * "countryCode": "US", * "phone": "2421642341", * "primary": false, * "_id": "cbbae95c-e1d5-48c4-a3ec-531ee2bf51fb" * } * ] * }, * "addresses": { * "items": [ * { * "tag": "HOME", * "address": { * "formatted": "3 Park Ave\nNY, New York 10010\nUnited States", * "addressLine1": "3 Park Ave", * "city": "NY", * "subdivision": "US-NY", * "country": "US", * "postalCode": "10010" * }, * "_id": "eeb4e174-fd0f-4ce8-8cac-dc152f284228" * } * ] * }, * "company": "Wix", * "jobTitle": "Writer", * "birthdate": "1995-04-25", * "locale": "en-us", * "labelKeys": { * "items": [ * "custom.contact" * ] * }, * "extendedFields": { * "items": { * "contacts.displayByLastName": "Doe John", * "invoices.vatId": "", * "emailSubscriptions.deliverabilityStatus": "NOT_SET", * "emailSubscriptions.subscriptionStatus": "UNSUBSCRIBED", * "contacts.displayByFirstName": "John Doe", * "custom.nickname": "Jonny" * } * } * }, * "_id": "2712ae1d-3f64-46c2-ac3a-94a6c2e29847", * "_createdDate": "2023-12-24T11:50:46.049Z", * "_updatedDate": "2023-12-25T07:31:48.270Z" * } * } */ ``` ## Update a contact by adding a phone number (export from backend code) ```javascript import { Permissions, webMethod } from 'wix-web-module'; import { contacts } from 'wix-crm.v2'; import { elevate } from 'wix-auth'; /* Sample contactId value: '2712ae1d-3f64-46c2-ac3a-94a6c2e29847' * * Sample revision value: '5' * * Sample info object: * { * phones: { * items: [ * { * countryCode:"US", * phone:"6465676359", * primary:true, * tag:"MOBILE" * }, * { * phone: "2421642341", * countryCode: "US", * primary: false, * tag: "HOME" * } * ] * } * } */ export const myUpdateContactFunction = webMethod(Permissions.Anyone, async (contactId, info, options) => { try { const elevatedUpdateContact = elevate(contacts.updateContact); const updatedContact = await elevatedUpdateContact(contactId, info, options); console.log('Successfully updated contact:', updatedContact) return updatedContact; } catch (error) { console.log(error); // Handle the error } }); /* Promise resolves to: * { * "contact": { * "revision": 17, * "source": { * "sourceType": "WIX_CODE", * "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a" * }, * "lastActivity": { * "activityDate": "2023-12-24T11:50:46.048Z", * "activityType": "CONTACT_CREATED" * }, * "primaryInfo": { * "email": "johndoe1@example.com", * "phone": "646-567-6359" * }, * "info": { * "name": { * "first": "John", * "last": "Doe" * }, * "emails": { * "items": [ * { * "tag": "UNTAGGED", * "email": "johndoe1@example.com", * "primary": true, * "_id": "37db3bde-83c0-4ca2-8097-88964a2f343b" * }, * { * "tag": "UNTAGGED", * "email": "john.doe.at.home@example.com", * "primary": false, * "_id": "06eef938-13d2-49f3-8097-60686ab4ddd2" * } * ] * }, * "phones": { * "items": [ * { * "tag": "MOBILE", * "countryCode": "US", * "phone": "646-567-6359", * "e164Phone": "+16465676359", * "primary": true, * "_id": "01e597c0-76c6-4791-bb77-8b3309f893d1" * }, * { * "tag": "HOME", * "countryCode": "US", * "phone": "2421642341", * "primary": false, * "_id": "cbbae95c-e1d5-48c4-a3ec-531ee2bf51fb" * } * ] * }, * "addresses": { * "items": [ * { * "tag": "HOME", * "address": { * "formatted": "3 Park Ave\nNY, New York 10010\nUnited States", * "addressLine1": "3 Park Ave", * "city": "NY", * "subdivision": "US-NY", * "country": "US", * "postalCode": "10010" * }, * "_id": "eeb4e174-fd0f-4ce8-8cac-dc152f284228" * } * ] * }, * "company": "Wix", * "jobTitle": "Writer", * "birthdate": "1995-04-25", * "locale": "en-us", * "labelKeys": { * "items": [ * "custom.contact" * ] * }, * "extendedFields": { * "items": { * "contacts.displayByLastName": "Doe John", * "invoices.vatId": "", * "emailSubscriptions.deliverabilityStatus": "NOT_SET", * "emailSubscriptions.subscriptionStatus": "UNSUBSCRIBED", * "contacts.displayByFirstName": "John Doe", * "custom.nickname": "Jonny" * } * } * }, * "_id": "2712ae1d-3f64-46c2-ac3a-94a6c2e29847", * "_createdDate": "2023-12-24T11:50:46.049Z", * "_updatedDate": "2023-12-25T07:31:48.270Z" * } * } */ ``` ## Force update a contact ```javascript /********************************** * Backend code - contacts.web.js * **********************************/ import { Permissions, webMethod } from 'wix-web-module'; import { contacts } from 'wix-crm.v2'; import { elevate } from 'wix-auth'; export const overwriteContactInfo = webMethod(Permissions.Anyone, async (contactId, updatedContactInfo) => { try { // Retrieve the contact const elevateGetContact = elevate(contacts.getContact); const contact = await elevateGetContact(contactId); // Extract revision number const revisionNumber = { revision: contact.revision }; // Update the contact const elevateUpdateContact = elevate(contacts.updateContact); const updatedContact = await elevateUpdateContact(contactId, updatedContactInfo, revisionNumber); return updatedContact; } catch (error) { console.log(error); // Handle the error } }); /************* * Page code * *************/ import { overwriteContactInfo } from 'backend/contacts.web'; $w.onReady(async function () { const contactId = "2712ae1d-3f64-46c2-ac3a-94a6c2e29847"; const updatedContactInfo = { name: { first: "John", last: "Mitchell" } }; async function updateContactName(){ try { const updatedContact = await overwriteContactInfo(contactId, updatedContactInfo); return updatedContact; } catch(error){ console.log(error); // Handle the error } } const result = await updateContactName(); const first = result.contact.info.name.first; const last = result.contact.info.name.last; console.log(`Updated contact name: ${first} ${last}`); }); ``` ---