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