Search.../

queryLabels( )

Developer Preview

Creates a query to retrieve a list of labels.

Description

The queryLabels() function builds a query to retrieve a list of labels and returns a LabelsQueryBuilder object.

The returned object contains the query definition, which is used to run the query using the find() function.

You can refine the query by chaining LabelsQueryBuilder functions onto the query. LabelsQueryBuilder functions enable you to filter, sort, and control the results that queryLabels() returns.

queryLabels() runs with the following LabelsQueryBuilder defaults, which you can override:

Note: Only visitors with Manage Contacts permissions can query labels.

The following LabelsQueryBuilder functions are supported for queryLabels(). For a full description of the Labels object, see the object returned for the items property in LabelsQueryResult.

PROPERTYSUPPORTED FILTERS & SORTING
namespaceeq(),ne()
keyeq(),ne(),in()
displayNameeq(),ne(),in(),startsWith(),ascending(),descending()
labelTypeeq()
_createdDateeq(),ne(),gt(),lt(),le(),ascending(),descending()
_updatedDateeq(),ne(),gt(),lt(),le(),ascending(),descending()
Admin Method

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

Syntax

function queryLabels(options: QueryLabelsOptions): LabelsQueryBuilder

queryLabels Parameters

NAME
TYPE
DESCRIPTION
options
Optional
QueryLabelsOptions

Language options.

Returns

Return Type:

Was this helpful?

Retrieve all labels

Copy Code
1import { labels } from 'wix-crm.v2';
2
3export async function myQueryLabelsFunction() {
4 try {
5
6 const queryResults = await labels.queryLabels()
7 .find();
8
9 const items = queryResults.items;
10 const firstItem = items[0];
11 const pageSize = queryResults.pageSize;
12 const hasNext = queryResults.hasNext();
13 const hasPrev = queryResults.hasPrev();
14 const length = queryResults.length;
15 const query = queryResults.query;
16
17 return items;
18
19 } catch (error) {
20
21 console.error(error);
22 // Handle the error
23
24 }
25}
26
27/* Returns items:
28 * [
29 * {
30 * "_createdDate": "2021-03-30T12:42:06.000Z",
31 * "_updatedDate": "2021-03-30T12:42:06.000Z",
32 * "displayName": "New Lead",
33 * "key": "custom.new-lead",
34 * "namespace": "custom",
35 * "labelType": "USER_DEFINED"
36 * },
37 * {
38 * "_createdDate": "2021-03-29T13:17:29.000Z",
39 * "_updatedDate": "2021-03-29T13:17:29.000Z",
40 * "displayName": "Marketing Your Business on Social Media",
41 * "key": "custom.marketing-your-business-on-social-media",
42 * "namespace": "custom",
43 * "labelType": "USER_DEFINED"
44 * },
45 * {
46 * "_createdDate": "2021-01-20T12:49:09.000Z",
47 * "_updatedDate": "2021-01-20T12:49:09.000Z",
48 * "displayName": "Quick Win",
49 * "key": "custom.quick-win",
50 * "namespace": "custom",
51 * "labelType": "USER_DEFINED"
52 * },
53 * {
54 * "_createdDate": "2021-01-20T12:48:46.000Z",
55 * "_updatedDate": "2021-01-20T12:48:46.000Z",
56 * "displayName": "Stale Lead",
57 * "key": "custom.stale-lead",
58 * "namespace": "custom",
59 * "labelType": "USER_DEFINED"
60 * },
61 * {
62 * "_createdDate": "2021-01-20T06:55:58.000Z",
63 * "_updatedDate": "2021-01-20T06:55:58.000Z",
64 * "displayName": "White Glove Treatment",
65 * "key": "custom.white-glove-treatment",
66 * "namespace": "custom",
67 * "labelType": "USER_DEFINED"
68 * },
69 * {
70 * "_createdDate": "2021-01-20T06:55:47.000Z",
71 * "_updatedDate": "2021-01-20T06:55:47.000Z",
72 * "displayName": "At Risk",
73 * "key": "custom.at-risk",
74 * "namespace": "custom",
75 * "labelType": "USER_DEFINED"
76 * },
77 * {
78 * "_createdDate": "2021-01-20T00:31:41.000Z",
79 * "_updatedDate": "2021-01-20T00:31:41.000Z",
80 * "displayName": "Active Customer",
81 * "key": "custom.active-customer",
82 * "namespace": "custom",
83 * "labelType": "USER_DEFINED"
84 * },
85 * {
86 * "_createdDate": "2021-01-19T21:38:49.000Z",
87 * "_updatedDate": "2021-01-20T19:07:54.000Z",
88 * "displayName": "Incoming",
89 * "key": "custom.incoming-leads",
90 * "namespace": "custom",
91 * "labelType": "USER_DEFINED"
92 * },
93 * {
94 * "displayName": "Customers",
95 * "key": "contacts.customers",
96 * "namespace": "contacts",
97 * "labelType": "SYSTEM"
98 * },
99 * {
100 * "displayName": "Contacted Me",
101 * "key": "contacts.contacted-me",
102 * "namespace": "contacts",
103 * "labelType": "SYSTEM"
104 * }
105 * ]
106 */