Search.../

getContact( )

Developer Preview

Retrieves a contact.

Description

The getContact() function returns a Promise that resolves when the contact is found.

Getting Merged Contacts

When a source contact is merged into 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()on merged contacts. Previously deleted source contact IDs can't be passed to any other function.

Note: Only visitors with Manage Contacts permissions can run this function.

Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function getContact(_id: string, options: GetContactOptions): Promise<Contact>

getContact Parameters

NAME
TYPE
DESCRIPTION
_id
string

ID of the contact to retrieve.

options
Optional
GetContactOptions

Get contact options.

Returns

The requested contact.

Return Type:

Promise<
Contact
>
NAME
TYPE
DESCRIPTION
_createdDate
Date

Date and time the contact was created.

_id
string

Contact ID.

_updatedDate
Date

Date and time the contact was last updated.

info
ContactInfo

Contact's details.

lastActivity
ContactActivity

Details about the contact's last action in the site.

primaryInfo
PrimaryContactInfo

Contact's primary phone and email.

This property reflects the email address in contactInfo.emails where primary is true.

revision
number

Revision number, which increments by 1 each time the contact is updated. To prevent conflicting changes, the existing revision must be used when updating a contact.

source
ContactSource

Details about the contact's source.

Was this helpful?

Get a contact by ID (dashboard page code)

Copy Code
1import { contacts } from 'wix-crm.v2';
2
3/* Sample contactId value: '2712ae1d-3f64-46c2-ac3a-94a6c2e29847' */
4
5export async function myGetContactFunction(id) {
6
7 try {
8 const contact = await contacts.getContact(id);
9 const contactId = contact._id;
10 const contactName = contact.info.name.first;
11
12 return contact;
13 } catch (error) {
14 console.log(error);
15 // Handle the error
16 }
17}
18
19/* Promise resolves to:
20 * {
21 * "revision": 1,
22 * "source": {
23 * "sourceType": "WIX_CODE",
24 * "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a"
25 * },
26 * "lastActivity": {
27 * "activityDate": "2023-12-24T11:50:46.048Z",
28 * "activityType": "CONTACT_CREATED"
29 * },
30 * "primaryInfo": {
31 * "email": "johndoe1@example.com",
32 * "phone": "6465676359"
33 * },
34 * "info": {
35 * "name": {
36 * "first": "John",
37 * "last": "Doe"
38 * },
39 * "emails": {
40 * "items": [
41 * {
42 * "tag": "UNTAGGED",
43 * "email": "johndoe1@example.com",
44 * "primary": true,
45 * "_id": "37db3bde-83c0-4ca2-8097-88964a2f343b"
46 * },
47 * ]
48 * },
49 * "phones": {
50 * "items": [
51 * {
52 * "tag": "MOBILE",
53 * "countryCode": "US",
54 * "phone": "646-567-6359",
55 * "e164Phone": "+16465676359",
56 * "primary": true,
57 * "_id": "ed1d7da0-b4a1-4164-81b7-c49dedc25dd7"
58 * }
59 * ]
60 * },
61 * "addresses": {
62 * "items": [
63 * {
64 * "tag": "HOME",
65 * "address": {
66 * "formatted": "3 Park Ave\nNY, New York 10010\nUnited States",
67 * "addressLine1": "3 Park Ave",
68 * "city": "NY",
69 * "subdivision": "US-NY",
70 * "country": "US",
71 * "postalCode": "10010"
72 * },
73 * "_id": "eeb4e174-fd0f-4ce8-8cac-dc152f284228"
74 * }
75 * ]
76 * },
77 * "company": "Wix",
78 * "jobTitle": "Writer",
79 * "birthdate": "1995-04-25",
80 * "locale": "en-us",
81 * "labelKeys": {
82 * "items": [
83 * "custom.contact"
84 * ]
85 * },
86 * "extendedFields": {
87 * "items": {
88 * "contacts.displayByLastName": "Doe John",
89 * "invoices.vatId": "",
90 * "emailSubscriptions.deliverabilityStatus": "NOT_SET",
91 * "emailSubscriptions.subscriptionStatus": "UNSUBSCRIBED",
92 * "contacts.displayByFirstName": "John Doe",
93 * "custom.nickname": "Jonny"
94 * }
95 * }
96 * },
97 * "_id": "2712ae1d-3f64-46c2-ac3a-94a6c2e29847",
98 * "_createdDate": "2023-12-24T11:50:46.049Z",
99 * "_updatedDate": "2023-12-24T12:50:46.047Z"
100 * }
101 */
102
Get a contact by ID (export from backend code)

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { contacts } from 'wix-crm.v2';
3import { elevate } from 'wix-auth';
4
5/* Sample contactId value: '2712ae1d-3f64-46c2-ac3a-94a6c2e29847' */
6
7export const myGetContactFunction = webMethod(Permissions.Anyone, async (id) => {
8
9 try {
10 const elevatedGetContact = elevate(contacts.getContact);
11 const contact = await elevatedGetContact(id);
12 const contactId = contact._id;
13 const contactName = contact.info.name.first;
14
15 return contact;
16 } catch (error) {
17 console.log(error);
18 // Handle the error
19 }
20});
21
22/* Promise resolves to:
23 * {
24 * "revision": 1,
25 * "source": {
26 * "sourceType": "WIX_CODE",
27 * "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a"
28 * },
29 * "lastActivity": {
30 * "activityDate": "2023-12-24T11:50:46.048Z",
31 * "activityType": "CONTACT_CREATED"
32 * },
33 * "primaryInfo": {
34 * "email": "johndoe1@example.com",
35 * "phone": "6465676359"
36 * },
37 * "info": {
38 * "name": {
39 * "first": "John",
40 * "last": "Doe"
41 * },
42 * "emails": {
43 * "items": [
44 * {
45 * "tag": "UNTAGGED",
46 * "email": "johndoe1@example.com",
47 * "primary": true,
48 * "_id": "37db3bde-83c0-4ca2-8097-88964a2f343b"
49 * },
50 * ]
51 * },
52 * "phones": {
53 * "items": [
54 * {
55 * "tag": "MOBILE",
56 * "countryCode": "US",
57 * "phone": "646-567-6359",
58 * "e164Phone": "+16465676359",
59 * "primary": true,
60 * "_id": "ed1d7da0-b4a1-4164-81b7-c49dedc25dd7"
61 * }
62 * ]
63 * },
64 * "addresses": {
65 * "items": [
66 * {
67 * "tag": "HOME",
68 * "address": {
69 * "formatted": "3 Park Ave\nNY, New York 10010\nUnited States",
70 * "addressLine1": "3 Park Ave",
71 * "city": "NY",
72 * "subdivision": "US-NY",
73 * "country": "US",
74 * "postalCode": "10010"
75 * },
76 * "_id": "eeb4e174-fd0f-4ce8-8cac-dc152f284228"
77 * }
78 * ]
79 * },
80 * "company": "Wix",
81 * "jobTitle": "Writer",
82 * "birthdate": "1995-04-25",
83 * "locale": "en-us",
84 * "labelKeys": {
85 * "items": [
86 * "custom.contact"
87 * ]
88 * },
89 * "extendedFields": {
90 * "items": {
91 * "contacts.displayByLastName": "Doe John",
92 * "invoices.vatId": "",
93 * "emailSubscriptions.deliverabilityStatus": "NOT_SET",
94 * "emailSubscriptions.subscriptionStatus": "UNSUBSCRIBED",
95 * "contacts.displayByFirstName": "John Doe",
96 * "custom.nickname": "Jonny"
97 * }
98 * }
99 * },
100 * "_id": "2712ae1d-3f64-46c2-ac3a-94a6c2e29847",
101 * "_createdDate": "2023-12-24T11:50:46.049Z",
102 * "_updatedDate": "2023-12-24T12:50:46.047Z"
103 * }
104 */