Search.../

queryLabels( )

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 control the results queryLabels() returns.

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

Note: Only visitors with Manage Contacts permissions can query labels. You can override the permissions by setting the suppressAuth option to true in the find() function.

For property support for filters and sorting, see Query labels: Supported filters and sorting.

Syntax

function queryLabels(): LabelsQueryBuilder

queryLabels Parameters

This function does not take any parameters.

Returns

A LabelsQueryBuilder object that contains the refined query.

Return Type:

Was this helpful?

Retrieve all labels

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