Search.../

getLabel( )

Developer Preview

Retrieves a label by the specified label key.

Description

The getLabel() function returns a Promise that resolves when the specified label is retrieved.

Admin Method

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
key
string

Label key.

key is generated when the label is created. It cannot be modified, even if displayName is updated.

options
Optional
GetLabelOptions

Language options.

Returns

The specified label.

Return Type:

Promise<
ContactLabel
>
NAME
TYPE
DESCRIPTION
_createdDate
Date

Date and time the label was created.

_updatedDate
Date

Date and time the label was last updated.

displayName
string

Label display name shown in the Dashboard.

key
string

Label key.

key is generated when the label is created. It cannot be modified, even if displayName is updated.

labelType
string

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.
namespace
string

Label namespace.

Labels created by site admins or 3rd-party apps are automatically assigned to the custom namespace.

namespaceDisplayName
string

Display name for the namespace, used to organize the list of labels in the site Dashboard.

Was this helpful?

Get a specified label (dashboard page code)

Copy Code
1import { labels } from 'wix-crm.v2';
2
3/* Sample key value: 'custom.at-risk' */
4
5export async function myGetLabelFunction(key) {
6
7 try {
8 const label = await labels.getLabel(key);
9 console.log('successfully retrieved label:', label);
10
11 return label;
12 } catch (error) {
13 console.log(error);
14 // Handle the error
15 }
16}
17
18/* 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 */
Get a specified label (export from backend code)

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { labels } from 'wix-crm.v2';
3import { elevate } from 'wix-auth';
4
5/* Sample key value: 'custom.at-risk' */
6
7export 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);
12
13 return label;
14 } catch (error) {
15 console.log(error);
16 // Handle the error
17 }
18});
19
20/* 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
Get the display name for a specified label

Copy Code
1import { labels } from 'wix-crm.v2';
2import { elevate } from 'wix-auth';
3
4/* Sample key value: 'custom.at-risk' */
5
6export async function myGetLabelFunction(key) {
7
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);
13
14 return displayName;
15 } catch (error) {
16 console.log(error);
17 // Handle the error
18 }
19}
20
21// Return value: "At Risk"
Get the display name for a specified label

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { labels } from 'wix-crm.v2';
3import { elevate } from 'wix-auth';
4
5/* Sample key value: 'custom.at-risk' */
6
7export 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);
13
14 return displayName;
15 } catch (error) {
16 console.log(error);
17 // Handle the error
18 }
19});
20
21// Return value: "At Risk"
22