Search.../

labelContact( )

Adds labels to a contact.

Description

The labelContact() function returns a Promise that resolves when the specified labels are added to the contact.

Note: Only visitors with Manage Contacts permissions can label contacts. You can override the permissions by setting the suppressAuth option to true.

Syntax

function labelContact(contactId: string, labelKeys: Array<string>, [options: AuthOptions]): Promise<Contact>

labelContact Parameters

NAME
TYPE
DESCRIPTION
contactId
string

ID of the contact to add labels to.

labelKeys
Array<string>

List of label keys to add to the contact.

Label keys must exist to be added to the contact. Contact labels can be created or retrieved with findOrCreateLabel() or queryLabels().

options
Optional
AuthOptions

Authorization options.

Returns

Fulfilled - Updated contact.

Return Type:

Promise<Contact>
NAME
TYPE
DESCRIPTION
_id
string

Contact ID.

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
Source

Details about the contact's source.

_createdDate
Date

Date and time the contact was created.

_updatedDate
Date

Date and time the contact was last updated.

lastActivity
LastActivity

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

primaryInfo
PrimaryInfo

Contact's primary phone and email.

info
Info

Contact's details.

Was this helpful?

Label a contact

Copy Code
1import { contacts } from 'wix-crm-backend';
2
3export function myLabelContactFunction() {
4 const contactId = "bc0ae72b-3285-485b-b0ad-c32c769a4daf";
5 const labelKeys = [
6 "custom.at-risk",
7 "custom.white-glove-treatment"
8 ];
9 const options = {
10 suppressAuth: false
11 };
12
13 return contacts.labelContact(contactId, labelKeys, options)
14 .then((labeledContact) => {
15 return labeledContact;
16 })
17 .catch((error) => {
18 console.error(error);
19 });
20}
21
22/* Promise resolves to:
23 * {
24 * "_id": "bc0ae72b-3285-485b-b0ad-c32c769a4daf",
25 * "_createdDate": "2021-03-30T13:12:39.650Z",
26 * "_updatedDate": "2021-04-07T21:01:25.892Z",
27 * "revision": 1,
28 * "info": {
29 * "name": {
30 * "first": "Gene",
31 * "last": "Lopez"
32 * },
33 * "birthdate": "1981-11-02",
34 * "jobTitle": "Senior Staff Attorney",
35 * "company": "Borer and Sons, Attorneys at Law",
36 * "locale": "en-us",
37 * "profilePicture": "https://randomuser.me/api/portraits/men/0.jpg",
38 * "addresses": [
39 * {
40 * "address": {
41 * "formatted": "9834 Bollinger Rd\nEl Cajon, WY 97766\nUS",
42 * "location": {
43 * "latitude": 84.1048,
44 * "longitude": -116.8836
45 * },
46 * "city": "El Cajon",
47 * "subdivision": "US-WY",
48 * "country": "US",
49 * "postalCode": "97766",
50 * "streetAddress": {
51 * "name": "Bollinger Rd",
52 * "number": "9834",
53 * "apt": ""
54 * }
55 * },
56 * "_id": "8532051f-91f2-42d9-9a97-9f2c39e64f7a",
57 * "tag": "HOME"
58 * }
59 * ],
60 * "emails": [
61 * {
62 * "_id": "5bdcce4a-37c2-46ed-b49c-d562c6e3c4ce",
63 * "tag": "HOME",
64 * "email": "gene.lopez.at.home@example.com",
65 * "primary": true
66 * },
67 * {
68 * "_id": "78e5f398-e148-448d-b490-7c0b7d2ab336",
69 * "tag": "WORK",
70 * "email": "gene.lopez@example.com",
71 * "primary": false
72 * }
73 * ],
74 * "phones": [
75 * {
76 * "_id": "820e4640-ffe0-4980-a097-62a715e73135",
77 * "tag": "MOBILE",
78 * "countryCode": "US",
79 * "phone": "(722)-138-3099",
80 * "primary": true
81 * },
82 * {
83 * "_id": "8506549e-e4f8-42f6-b6fc-9db155b582ef",
84 * "tag": "HOME",
85 * "countryCode": "US",
86 * "phone": "(704)-454-1233",
87 * "e164Phone": "+17044541233",
88 * "primary": false
89 * }
90 * ],
91 * "labelKeys": [
92 * "custom.white-glove-treatment",
93 * "contacts.contacted-me",
94 * "custom.new-lead",
95 * "custom.at-risk"
96 * ],
97 * "extendedFields": {
98 * "contacts.displayByLastName": "Lopez Gene",
99 * "emailSubscriptions.deliverabilityStatus": "NOT_SET",
100 * "emailSubscriptions.subscriptionStatus": "NOT_SET",
101 * "custom.event-we-met-at": "LegalBigData",
102 * "emailSubscriptions.effectiveEmail": "gene.lopez.at.home@example.com",
103 * "contacts.displayByFirstName": "Gene Lopez"
104 * }
105 * },
106 * "lastActivity": {
107 * "activityDate": "2021-03-30T13:12:39.649Z",
108 * "activityType": "CONTACT_CREATED"
109 * },
110 * "primaryInfo": {
111 * "email": "gene.lopez.at.home@example.com",
112 * "phone": "(722)-138-3099"
113 * },
114 * "source": {
115 * "sourceType": "OTHER"
116 * }
117 * }
118 */