getLabel( )
Retrieves a label by the specified label key.
Description
The getLabel()
function returns a Promise that resolves when the specified label is retrieved.
This function requires elevated permissions to run. This function is not universal and runs only on the backend.
Syntax
function getLabel(key: string, options: GetLabelOptions): Promise<ContactLabel>
getLabel Parameters
NAME
TYPE
DESCRIPTION
Label key.
key
is generated when the label is created.
It cannot be modified, even if displayName
is updated.
Language options.
Returns
The specified label.
Return Type:
NAME
TYPE
DESCRIPTION
Date and time the label was created.
Date and time the label was last updated.
Label display name shown in the Dashboard.
Label key.
key
is generated when the label is created.
It cannot be modified, even if displayName
is updated.
Label type.
"SYSTEM"
: The label is a default system label for the Contact List."USER_DEFINED"
: The label was created by a site contributor or 3rd-party app."WIX_APP_DEFINED"
: The label was created by a Wix app.
Label namespace.
Labels created by site admins or 3rd-party apps
are automatically assigned to the custom
namespace.
Display name for the namespace, used to organize the list of labels in the site Dashboard.
Was this helpful?
1import { labels } from 'wix-crm.v2';23/* Sample key value: 'custom.at-risk' */45export async function myGetLabelFunction(key) {67 try {8 const label = await labels.getLabel(key);9 console.log('successfully retrieved label:', label);1011 return label;12 } catch (error) {13 console.log(error);14 // Handle the error15 }16}1718/* Promise resolves to:19 * {20 * "namespace": "custom",21 * "namespaceDisplayName": "Labels",22 * "key": "custom.at-risk",23 * "displayName": "At Risk",24 * "labelType": "USER_DEFINED",25 * "legacyId": "65bd6a68-e10e-4831-8d92-c90e75be1570",26 * "_createdDate": "2023-12-25T08:38:36.000Z",27 * "_updatedDate": "2023-12-25T08:38:36.000Z"28 * }29 */
1import { Permissions, webMethod } from 'wix-web-module';2import { labels } from 'wix-crm.v2';3import { elevate } from 'wix-auth';45/* Sample key value: 'custom.at-risk' */67export const myGetLabelFunction = webMethod(Permissions.Anyone, async (key) => {8 try {9 const elevatedGetLabel = elevate(labels.getLabel);10 const label = await elevatedGetLabel(key);11 console.log('successfully retrieved label:', label);1213 return label;14 } catch (error) {15 console.log(error);16 // Handle the error17 }18});1920/* Promise resolves to:21 * {22 * "namespace": "custom",23 * "namespaceDisplayName": "Labels",24 * "key": "custom.at-risk",25 * "displayName": "At Risk",26 * "labelType": "USER_DEFINED",27 * "legacyId": "65bd6a68-e10e-4831-8d92-c90e75be1570",28 * "_createdDate": "2023-12-25T08:38:36.000Z",29 * "_updatedDate": "2023-12-25T08:38:36.000Z"30 * }31 */32
1import { labels } from 'wix-crm.v2';2import { elevate } from 'wix-auth';34/* Sample key value: 'custom.at-risk' */56export async function myGetLabelFunction(key) {78 try {9 const elevatedGetLabel = elevate(labels.getLabel);10 const label = await elevatedGetLabel(key);11 const displayName = label.displayName;12 console.log('successfully retrieved the display name:', displayName);1314 return displayName;15 } catch (error) {16 console.log(error);17 // Handle the error18 }19}2021// Return value: "At Risk"
1import { Permissions, webMethod } from 'wix-web-module';2import { labels } from 'wix-crm.v2';3import { elevate } from 'wix-auth';45/* Sample key value: 'custom.at-risk' */67export const myGetLabelFunction = webMethod(Permissions.Anyone, async (key) => {8 try {9 const elevatedGetLabel = elevate(labels.getLabel);10 const label = await elevatedGetLabel(key);11 const displayName = label.displayName;12 console.log('successfully retrieved the display name:', displayName);1314 return displayName;15 } catch (error) {16 console.log(error);17 // Handle the error18 }19});2021// Return value: "At Risk"22