queryLabels( )


Creates a query to retrieve a list of labels.

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.

Method Declaration
Copy
function queryLabels(): LabelsQueryBuilder;
Request
This method does not take any parameters
Returns
Return Type:LabelsQueryBuilder
Retrieve all labels
JavaScript
import { Permissions, webMethod } from "wix-web-module"; import { contacts } from "wix-crm-backend"; export const myQueryLabelsFunction = webMethod( Permissions.Anyone, async (options) => { try { const queryResults = await contacts.queryLabels().find(options); const items = queryResults.items; const firstItem = items[0]; const pageSize = queryResults.pageSize; const hasNext = queryResults.hasNext(); const hasPrev = queryResults.hasPrev(); const length = queryResults.length; const query = queryResults.query; return items; } catch (error) { console.error(error); // Handle the error } }, ); /* Returns items: * [ * { * "_createdDate": "2021-03-30T12:42:06.000Z", * "_updatedDate": "2021-03-30T12:42:06.000Z", * "displayName": "New Lead", * "key": "custom.new-lead", * "namespace": "custom", * "labelType": "USER_DEFINED" * }, * { * "_createdDate": "2021-03-29T13:17:29.000Z", * "_updatedDate": "2021-03-29T13:17:29.000Z", * "displayName": "Marketing Your Business on Social Media", * "key": "custom.marketing-your-business-on-social-media", * "namespace": "custom", * "labelType": "USER_DEFINED" * }, * { * "_createdDate": "2021-01-20T12:49:09.000Z", * "_updatedDate": "2021-01-20T12:49:09.000Z", * "displayName": "Quick Win", * "key": "custom.quick-win", * "namespace": "custom", * "labelType": "USER_DEFINED" * }, * { * "_createdDate": "2021-01-20T12:48:46.000Z", * "_updatedDate": "2021-01-20T12:48:46.000Z", * "displayName": "Stale Lead", * "key": "custom.stale-lead", * "namespace": "custom", * "labelType": "USER_DEFINED" * }, * { * "_createdDate": "2021-01-20T06:55:58.000Z", * "_updatedDate": "2021-01-20T06:55:58.000Z", * "displayName": "White Glove Treatment", * "key": "custom.white-glove-treatment", * "namespace": "custom", * "labelType": "USER_DEFINED" * }, * { * "_createdDate": "2021-01-20T06:55:47.000Z", * "_updatedDate": "2021-01-20T06:55:47.000Z", * "displayName": "At Risk", * "key": "custom.at-risk", * "namespace": "custom", * "labelType": "USER_DEFINED" * }, * { * "_createdDate": "2021-01-20T00:31:41.000Z", * "_updatedDate": "2021-01-20T00:31:41.000Z", * "displayName": "Active Customer", * "key": "custom.active-customer", * "namespace": "custom", * "labelType": "USER_DEFINED" * }, * { * "_createdDate": "2021-01-19T21:38:49.000Z", * "_updatedDate": "2021-01-20T19:07:54.000Z", * "displayName": "Incoming", * "key": "custom.incoming-leads", * "namespace": "custom", * "labelType": "USER_DEFINED" * }, * { * "displayName": "Customers", * "key": "contacts.customers", * "namespace": "contacts", * "labelType": "SYSTEM" * }, * { * "displayName": "Contacted Me", * "key": "contacts.contacted-me", * "namespace": "contacts", * "labelType": "SYSTEM" * } * ] */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?