Search.../

unlabelContact( )

Removes labels from a contact.

Description

The unlabelContact() function returns a Promise that resolves when the specified labels are removed from the contact.

If a label is no longer needed and you want to remove it from all contacts, you can remove it with the Labels deleteLabel() function.

Admin Method

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

Syntax

function unlabelContact(contactId: string, labelKeys: Array<string>): Promise<UnlabelContactResponse>

unlabelContact Parameters

NAME
TYPE
DESCRIPTION
contactId
string

ID of the contact to remove labels from.

labelKeys
Array<
string
>

List of label keys to remove from the contact.

Returns

Updated contact.

Return Type:

Promise<
UnlabelContactResponse
>
NAME
TYPE
DESCRIPTION
contact
Contact

Updated contact.

Was this helpful?

Remove a label from a contact (dashboard page code)

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