labelContact( )
Adds labels to a contact.
Description
The labelContact()
function returns a Promise
that resolves when the specified labels are added to the contact.
- To create new labels: Use
findOrCreateLabel()
. - To find labels: Use
findOrCreateLabel()
,getLabel()
, orqueryLabels()
.
Note: Only visitors with Manage Contacts permissions can label contacts. You can override the permissions by setting the
suppressAuth
option totrue
.
Syntax
function labelContact(contactId: string, labelKeys: Array<string>, [options: AuthOptions]): Promise<Contact>
labelContact Parameters
NAME
TYPE
DESCRIPTION
ID of the contact to add labels to.
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()
.
Authorization options.
Returns
Fulfilled - Updated contact.
Return Type:
NAME
TYPE
DESCRIPTION
Contact ID.
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.
Details about the contact's source.
Date and time the contact was created.
Date and time the contact was last updated.
Details about the contact's last action in the site.
Contact's primary phone and email.
Contact's details.
Was this helpful?
Label a contact
1import { Permissions, webMethod } from 'wix-web-module';2import { contacts } from 'wix-crm-backend';34export const myLabelContactFunction = webMethod(Permissions.Anyone, () => {5 const contactId = "bc0ae72b-3285-485b-b0ad-c32c769a4daf";6 const labelKeys = [7 "custom.at-risk",8 "custom.white-glove-treatment"9 ];10 const options = {11 suppressAuth: false12 };1314 return contacts.labelContact(contactId, labelKeys, options)15 .then((labeledContact) => {16 return labeledContact;17 })18 .catch((error) => {19 console.error(error);20 });21});2223/* Promise resolves to:24 * {25 * "_id": "bc0ae72b-3285-485b-b0ad-c32c769a4daf",26 * "_createdDate": "2021-03-30T13:12:39.650Z",27 * "_updatedDate": "2021-04-07T21:01:25.892Z",28 * "revision": 1,29 * "info": {30 * "name": {31 * "first": "Gene",32 * "last": "Lopez"33 * },34 * "birthdate": "1981-11-02",35 * "jobTitle": "Senior Staff Attorney",36 * "company": "Borer and Sons, Attorneys at Law",37 * "locale": "en-us",38 * "profilePicture": "https://randomuser.me/api/portraits/men/0.jpg",39 * "addresses": [40 * {41 * "address": {42 * "formatted": "9834 Bollinger Rd\nEl Cajon, WY 97766\nUS",43 * "location": {44 * "latitude": 84.1048,45 * "longitude": -116.883646 * },47 * "city": "El Cajon",48 * "subdivision": "US-WY",49 * "country": "US",50 * "postalCode": "97766",51 * "streetAddress": {52 * "name": "Bollinger Rd",53 * "number": "9834",54 * "apt": ""55 * }56 * },57 * "_id": "8532051f-91f2-42d9-9a97-9f2c39e64f7a",58 * "tag": "HOME"59 * }60 * ],61 * "emails": [62 * {63 * "_id": "5bdcce4a-37c2-46ed-b49c-d562c6e3c4ce",64 * "tag": "HOME",65 * "email": "gene.lopez.at.home@example.com",66 * "primary": true67 * },68 * {69 * "_id": "78e5f398-e148-448d-b490-7c0b7d2ab336",70 * "tag": "WORK",71 * "email": "gene.lopez@example.com",72 * "primary": false73 * }74 * ],75 * "phones": [76 * {77 * "_id": "820e4640-ffe0-4980-a097-62a715e73135",78 * "tag": "MOBILE",79 * "countryCode": "US",80 * "phone": "(722)-138-3099",81 * "primary": true82 * },83 * {84 * "_id": "8506549e-e4f8-42f6-b6fc-9db155b582ef",85 * "tag": "HOME",86 * "countryCode": "US",87 * "phone": "(704)-454-1233",88 * "e164Phone": "+17044541233",89 * "primary": false90 * }91 * ],92 * "labelKeys": [93 * "custom.white-glove-treatment",94 * "contacts.contacted-me",95 * "custom.new-lead",96 * "custom.at-risk"97 * ],98 * "extendedFields": {99 * "contacts.displayByLastName": "Lopez Gene",100 * "emailSubscriptions.deliverabilityStatus": "NOT_SET",101 * "emailSubscriptions.subscriptionStatus": "NOT_SET",102 * "custom.event-we-met-at": "LegalBigData",103 * "emailSubscriptions.effectiveEmail": "gene.lopez.at.home@example.com",104 * "contacts.displayByFirstName": "Gene Lopez"105 * }106 * },107 * "lastActivity": {108 * "activityDate": "2021-03-30T13:12:39.649Z",109 * "activityType": "CONTACT_CREATED"110 * },111 * "primaryInfo": {112 * "email": "gene.lopez.at.home@example.com",113 * "phone": "(722)-138-3099"114 * },115 * "source": {116 * "sourceType": "OTHER"117 * }118 * }119 */