> 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: getContact(contactId: string, options: AuthOptions) # Method package: wixCrmBackend # Method menu location: wixCrmBackend --> Contacts --> getContact # Method Link: https://dev.wix.com/docs/velo/apis/wix-crm-backend/contacts/get-contact.md # Method Description: Retrieves a contact. The `getContact()` function returns a Promise that resolves when the contact is found. #### Getting Merged Contacts When a source contact is merged with a target contact, the source contact is deleted. When calling `getContact()` for a merged contact, you can use the source or target contact ID. In both cases, the target contact is returned. This is supported only when calling `getContact()`, and only for merged contacts. Deleted source contact IDs are not supported on any other function. > **Notes:** > > - This function replaces the deprecated > `wixCrmBackend.getContactById()`. > The deprecated function will continue to work, but it will not receive updates. > To keep any existing code compatible with future changes, see the > [migration instructions](https://dev.wix.com/docs/velo/api-reference/wix-crm-backend/get-contact-by-id.md). > - Only visitors with > **Manage Contacts** [permissions](https://www.wix.com/my-account/site-selector/?buttonText=Select%20Site&title=Select%20a%20Site&autoSelectOnSingleSite=true&actionUrl=https:%2F%2Fwww.wix.com%2Fdashboard%2F%7B%7BmetaSiteId%7D%7D%2Froles-and-permissions) > can retrieve contacts. > You can override the permissions by setting the `suppressAuth` option to `true`. # Method Code Examples: *** Note: do not assume any prop names or enum values other than the ones in the example. ## Get a contact ```javascript import { Permissions, webMethod } from 'wix-web-module'; import { contacts } from 'wix-crm-backend'; export const myGetContactFunction = webMethod(Permissions.Anyone, () => { const contactId = "bc0ae72b-3285-485b-b0ad-c32c769a4daf"; const options = { suppressAuth: false }; return contacts.getContact(contactId, options) .then((contact) => { return contact; }) .catch((error) => { console.error(error); }); }); /* Promise resolves to: * { * "_id": "bc0ae72b-3285-485b-b0ad-c32c769a4daf", * "_createdDate": "2021-03-30T13:12:39.650Z", * "_updatedDate": "2021-03-30T13:12:39.650Z", * "revision": 0, * "info": { * "name": { * "first": "Gene", * "last": "Lopez" * }, * "birthdate": "1981-11-02", * "company": "Borer and Sons, Attorneys at Law", * "jobTitle": "Senior Staff Attorney", * "labelKeys": [ * "custom.white-glove-treatment", * "contacts.contacted-me", * "custom.new-lead" * ], * "locale": "en-us", * "emails": [ * { * "_id": "5bdcce4a-37c2-46ed-b49c-d562c6e3c4ce", * "tag": "HOME", * "email": "gene.lopez.at.home@example.com", * "primary": true * }, * { * "_id": "78e5f398-e148-448d-b490-7c0b7d2ab336", * "tag": "WORK", * "email": "gene.lopez@example.com", * "primary": false * } * ], * "phones": [ * { * "_id": "820e4640-ffe0-4980-a097-62a715e73135", * "tag": "MOBILE", * "countryCode": "US", * "phone": "(722)-138-3099", * "primary": true * }, * { * "_id": "8506549e-e4f8-42f6-b6fc-9db155b582ef", * "tag": "HOME", * "countryCode": "US", * "phone": "(704)-454-1233", * "e164Phone": "+17044541233", * "primary": false * } * ], * "addresses": [ * { * "address": { * "formatted": "9834 Bollinger Rd\nEl Cajon, WY 97766\nUS", * "location": { * "latitude": 84.1048, * "longitude": -116.8836 * }, * "city": "El Cajon", * "subdivision": "US-WY", * "country": "US", * "postalCode": "97766", * "streetAddress": { * "name": "Bollinger Rd", * "number": "9834", * "apt": "" * } * }, * "_id": "8532051f-91f2-42d9-9a97-9f2c39e64f7a", * "tag": "HOME" * } * ], * "profilePicture": "https://randomuser.me/api/portraits/men/0.jpg", * "extendedFields": { * "contacts.displayByLastName": "Lopez Gene", * "emailSubscriptions.deliverabilityStatus": "NOT_SET", * "emailSubscriptions.subscriptionStatus": "NOT_SET", * "custom.event-we-met-at": "LegalBigData", * "emailSubscriptions.effectiveEmail": "gene.lopez.at.home@example.com", * "contacts.displayByFirstName": "Gene Lopez" * } * }, * "lastActivity": { * "activityDate": "2021-03-30T13:12:39.649Z", * "activityType": "CONTACT_CREATED" * }, * "primaryInfo": { * "email": "gene.lopez.at.home@example.com", * "phone": "(722)-138-3099" * }, * "source": { * "sourceType": "OTHER" * } * } */ ``` ## Get a contact's latest revision number, then update ```javascript /******************************* * Backend code - contacts.web.js * *******************************/ import { Permissions, webMethod } from 'wix-web-module'; import { contacts } from 'wix-crm-backend'; export const overwriteContactInfo = webMethod(Permissions.Anyone, async (contactId, updatedContactInfo) => { // Get the contact's last revision number const myContact = await contacts.getContact(contactId); const contactIdentifiers = { contactId: contactId, revision: myContact.revision }; const options = { allowDuplicates: false, suppressAuth: false }; return await contacts.updateContact(contactIdentifiers, updatedContactInfo, options); }); /************* * Page code * *************/ import { overwriteContactInfo } from 'backend/contacts.web'; // ... const contactId = "0677ef55-cf20-4f68-989a-f31d3649eb72"; const updatedContactInfo = { name: { first: "Annie", last: "New Name" } }; overwriteContactInfo(contactId, updatedContactInfo) .then((updatedContact) => { return updatedContact; }) .catch((error) => { console.error(error); }); /* Updated contact resolves to: * { * "_id": "0677ef55-cf20-4f68-989a-f31d3649eb72", * "_createdDate": "2021-03-31T20:24:48.393Z", * "_updatedDate": "2021-03-31T20:29:14.519Z", * "revision": 4, * "info": { * "name": { * "first": "Annie", * "last": "New Name" * }, * "extendedFields": { * "contacts.displayByFirstName": "Annie New Name", * "contacts.displayByLastName": "New Name Annie" * } * }, * "lastActivity": { * "activityDate": "2021-03-31T20:24:48.393Z", * "activityType": "CONTACT_CREATED" * }, * "source": { * "appId": "manual", * "sourceType": "ADMIN" * } * } */ ``` ## Get a merged source contact ```javascript import { Permissions, webMethod } from 'wix-web-module'; import { contacts } from 'wix-crm-backend'; /* Sample contactId value: * 'c8e08afd-deac-40f7-b4c1-b42409d35df7' */ export const myGetContactFunction = webMethod(Permissions.Anyone, async (contactId) => { try { const retrievedContact = await contacts.getContact(contactId); const retrievedContactId = retrievedContact._id; if (retrievedContactId !== contactId) { console.log(`Merged target contact ${retrievedContactId} returned. The requested contact was deleted in the merge.`); } return retrievedContact; } catch (error) { console.error(error); // Handle the error } }); /* Promise resolves to: * { * "_id": "49c5d809-6bc8-40b1-86e7-4bf3f6d17adb", * "_createdDate": "2022-02-02T21:41:03.313Z", * "_updatedDate": "2022-02-02T21:52:00.048Z", * "revision": 6, * "lastActivity": { * "activityDate": "2022-02-02T21:51:59.952Z", * "activityType": "CONTACT_MERGED" * }, * "primaryInfo": { * "email": "target.contact@example.com", * "phone": "62183848" * }, * "info": { * "name": { * "first": "Updated Target" * }, * "emails": [ * { * "_id": "81109065-7b9e-4b99-b146-b523eb5338ca", * "tag": "HOME", * "email": "target.contact@example.com", * "primary": true * }, * { * "_id": "cd9ea33c-4358-457f-bd99-4384cf5f83c2", * "tag": "WORK", * "email": "source.contact@example.com", * "primary": false * } * ], * "addresses": [ * { * "address": { * "formatted": "4197 Existing Street Address\nHovedstaden Klitmøller\nDenmark", * "city": "Klitmøller", * "country": "DK", * "postalCode": "Hovedstaden", * "addressLine1": "4197 Existing Street Address" * }, * "_id": "a3455bd0-76af-427c-9adc-8d384193f347", * "tag": "HOME" * }, * { * "address": { * "formatted": "9278 Source Street\n31562 København S\nDenmark", * "city": "København S", * "subdivision": "DK-82", * "country": "DK", * "postalCode": "31562", * "addressLine1": "9278 Source Street" * }, * "_id": "c3bb555c-a543-4e0a-86e3-341ced30666c", * "tag": "WORK" * } * ], * "phones": [ * { * "_id": "5a53acb4-fd19-411e-93f3-3bd7ca8f9df8", * "tag": "HOME", * "countryCode": "DK", * "phone": "62183848", * "e164Phone": "+4562183848", * "formattedPhone": "+45 62183848", * "primary": true * }, * { * "_id": "b98e5caf-95d6-4fab-b80c-267431b82344", * "tag": "WORK", * "countryCode": "DK", * "phone": "64498094", * "e164Phone": "+4564498094", * "formattedPhone": "+45 64498094", * "primary": false * } * ], * "labelKeys": [ * "contacts.contacted-me" * ], * "extendedFields": { * "contacts.displayByLastName": "Updated Target", * "invoices.vatId": "", * "emailSubscriptions.deliverabilityStatus": "NOT_SET", * "emailSubscriptions.subscriptionStatus": "NOT_SET", * "emailSubscriptions.effectiveEmail": "source.contact@example.com", * "contacts.displayByFirstName": "Updated Target" * }, * "profilePicture": "https://img-wixmp-8be454c954980f083caba37c.wixmp.com/sites/7b940519-404c-4972-9f03-9a430b68d52c/49c5d809-6bc8-40b1-86e7-4bf3f6d17adb/ecb8b31b-845c-4bc6-b868-73df78a92313-avatar-v2.jpeg::fil:100_100" * }, * "source": { * "sourceType": "ADMIN" * } */ ``` ---