> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # Method name: queryLabels(options: QueryLabelsOptions) # Method package: wixCrmV2 # Method menu location: wixCrmV2 --> labels --> queryLabels # Method Link: https://dev.wix.com/docs/velo/apis/wix-crm-v2/labels/query-labels.md # Method Description: Creates a query to retrieve a list of labels. The `queryLabels()` method 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 call the query using the `find()` method. You can refine the query by chaining `LabelsQueryBuilder` methods onto the query. `LabelsQueryBuilder` methods enable you to filter, sort, and control the response that `queryLabels()` returns. `queryLabels()` is called with the following `LabelsQueryBuilder` defaults, which you can override: - `skip(0)` - `limit(50)` - `descending('_createdDate')` The following `LabelsQueryBuilder` methods are supported for `queryLabels()`. For a full description of the `Labels` object, see the object returned for the `items` field in `LabelsQueryResult`. |PROPERTY |SUPPORTED FILTERS & SORTING |:---:|:---:| |`namespace`|[`eq()`](/labels-query-builder/eq),[`ne()`](/labels-query-builder/ne)| |`key`|[`eq()`](/labels-query-builder/eq),[`ne()`](/labels-query-builder/ne),[`in()`](/labels-query-builder/in)| |`displayName`|[`eq()`](/labels-query-builder/eq),[`ne()`](/labels-query-builder/ne),[`in()`](/labels-query-builder/in),[`startsWith()`](/labels-query-builder/starts-with),[`ascending()`](/labels-query-builder/ascending),[`descending()`](/labels-query-builder/descending)| |`labelType`|[`eq()`](/labels-query-builder/eq)| |`_createdDate`|[`eq()`](/labels-query-builder/eq),[`ne()`](/labels-query-builder/ne),[`gt()`](/labels-query-builder/gt),[`lt()`](/labels-query-builder/lt),[`ge()`](/labels-query-builder/ge),[`le()`](/labels-query-builder/le),[`ascending()`](/labels-query-builder/ascending),[`descending()`](/labels-query-builder/descending)| |`_updatedDate`|[`eq()`](/labels-query-builder/eq),[`ne()`](/labels-query-builder/ne),[`gt()`](/labels-query-builder/gt),[`lt()`](/labels-query-builder/lt),[`ge()`](/labels-query-builder/ge),[`le()`](/labels-query-builder/le),[`ascending()`](/labels-query-builder/ascending),[`descending()`](/labels-query-builder/descending)| # Method Code Examples: *** Note: do not assume any prop names or enum values other than the ones in the example. ## Retrieve all labels (dashboard page code) ```javascript import { labels } from 'wix-crm.v2'; export async function myQueryLabelsFunction() { try { const queryResults = await labels.queryLabels() .find(); 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; console.log('Retrieved items:', items); return items; } catch (error) { console.log(error); // Handle the error } } /* Returns items: * [ * { * "namespace": "custom", * "namespaceDisplayName": "Labels", * "key": "custom.at-risk", * "displayName": "At Risk", * "labelType": "USER_DEFINED", * "legacyId": "65bd6a68-e10e-4831-8d92-c90e75be1570", * "_createdDate": "2023-12-25T08:38:36.000Z", * "_updatedDate": "2023-12-25T08:38:36.000Z" * }, * { * "namespace": "custom", * "namespaceDisplayName": "Labels", * "key": "custom.active-customer", * "displayName": "Active Customer", * "labelType": "USER_DEFINED", * "legacyId": "74f1e5c6-d9d5-4485-b272-13081ea35f38", * "_createdDate": "2023-12-25T06:13:21.000Z", * "_updatedDate": "2023-12-25T06:13:21.000Z" * }, * { * "namespace": "custom", * "namespaceDisplayName": "Labels", * "key": "custom.contact", * "displayName": "Contact", * "labelType": "USER_DEFINED", * "legacyId": "5fec05f8-eb03-4243-ad46-4c24535144f6", * "_createdDate": "2023-12-11T07:33:35.000Z", * "_updatedDate": "2023-12-11T07:33:35.000Z" * }, * { * "namespace": "contacts", * "namespaceDisplayName": "Labels", * "key": "contacts.customers", * "displayName": "Customers", * "labelType": "SYSTEM", * "legacyId": "contacts_server/customers" * }, * { * "namespace": "contacts", * "namespaceDisplayName": "Labels", * "key": "contacts.contacted-me", * "displayName": "Contacted Me", * "labelType": "SYSTEM", * "legacyId": "contacts_server/contacted_me" * } * ] */ ``` ## Retrieve all labels (export from backend code) ```javascript import { Permissions, webMethod } from 'wix-web-module'; import { labels } from 'wix-crm.v2'; import { elevate } from 'wix-auth'; export const myQueryLabelsFunction = webMethod(Permissions.Anyone, async () => { try { const elevatedQueryLabels = elevate(labels.queryLabels); const queryResults = await elevatedQueryLabels() .find(); 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; console.log('Retrieved items:', items); return items; } catch (error) { console.log(error); // Handle the error } }); /* Returns items: * [ * { * "namespace": "custom", * "namespaceDisplayName": "Labels", * "key": "custom.at-risk", * "displayName": "At Risk", * "labelType": "USER_DEFINED", * "legacyId": "65bd6a68-e10e-4831-8d92-c90e75be1570", * "_createdDate": "2023-12-25T08:38:36.000Z", * "_updatedDate": "2023-12-25T08:38:36.000Z" * }, * { * "namespace": "custom", * "namespaceDisplayName": "Labels", * "key": "custom.active-customer", * "displayName": "Active Customer", * "labelType": "USER_DEFINED", * "legacyId": "74f1e5c6-d9d5-4485-b272-13081ea35f38", * "_createdDate": "2023-12-25T06:13:21.000Z", * "_updatedDate": "2023-12-25T06:13:21.000Z" * }, * { * "namespace": "custom", * "namespaceDisplayName": "Labels", * "key": "custom.contact", * "displayName": "Contact", * "labelType": "USER_DEFINED", * "legacyId": "5fec05f8-eb03-4243-ad46-4c24535144f6", * "_createdDate": "2023-12-11T07:33:35.000Z", * "_updatedDate": "2023-12-11T07:33:35.000Z" * }, * { * "namespace": "contacts", * "namespaceDisplayName": "Labels", * "key": "contacts.customers", * "displayName": "Customers", * "labelType": "SYSTEM", * "legacyId": "contacts_server/customers" * }, * { * "namespace": "contacts", * "namespaceDisplayName": "Labels", * "key": "contacts.contacted-me", * "displayName": "Contacted Me", * "labelType": "SYSTEM", * "legacyId": "contacts_server/contacted_me" * } * ] */ ``` ## Retrieve labels with specified `labelType` ```javascript import { Permissions, webMethod } from 'wix-web-module'; import { labels } from 'wix-crm.v2'; import { elevate } from 'wix-auth'; export const myQueryLabelsFunction = webMethod(Permissions.Anyone, async () => { try { const elevatedQueryLabels = elevate(labels.queryLabels); const queryResults = await elevatedQueryLabels() .eq("labelType", "USER_DEFINED") .find(); 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; console.log('Retrieved items:', items); return items; } catch (error) { console.log(error); // Handle the error } }); /* Returns items: * [ * { * "namespace": "custom", * "namespaceDisplayName": "Labels", * "key": "custom.at-risk", * "displayName": "At Risk", * "labelType": "USER_DEFINED", * "legacyId": "65bd6a68-e10e-4831-8d92-c90e75be1570", * "_createdDate": "2023-12-25T08:38:36.000Z", * "_updatedDate": "2023-12-25T08:38:36.000Z" * }, * { * "namespace": "custom", * "namespaceDisplayName": "Labels", * "key": "custom.active-customer", * "displayName": "Active Customer", * "labelType": "USER_DEFINED", * "legacyId": "74f1e5c6-d9d5-4485-b272-13081ea35f38", * "_createdDate": "2023-12-25T06:13:21.000Z", * "_updatedDate": "2023-12-25T06:13:21.000Z" * }, * { * "namespace": "custom", * "namespaceDisplayName": "Labels", * "key": "custom.contact", * "displayName": "Contact", * "labelType": "USER_DEFINED", * "legacyId": "5fec05f8-eb03-4243-ad46-4c24535144f6", * "_createdDate": "2023-12-11T07:33:35.000Z", * "_updatedDate": "2023-12-11T07:33:35.000Z" * } * ] */ ``` ## Add labels to a contact form as checkbox options ```javascript /********************************** * Backend code - contacts.web.js * **********************************/ import { Permissions, webMethod } from 'wix-web-module'; import { labels } from 'wix-crm.v2'; import { elevate } from 'wix-auth'; export const addLabelsAsCheckboxOptions = webMethod(Permissions.Anyone, async () => { try { // Query specific labels to use as checkbox options const elevatedQueryLabels = elevate(labels.queryLabels); const myLabels = await elevatedQueryLabels() .startsWith('displayName', "Contact by") .find(); return myLabels.items } catch (error) { console.log(error); // Handle the error } }); /************* * Page code * *************/ import { addLabelsAsCheckboxOptions } from 'backend/labelsBackend.web'; // Trigger when the email input field on a contact form is clicked export async function inputEmail_click_1(event) { try { let checkboxLabelOptions = []; const labels = await addLabelsAsCheckboxOptions(); // Add label display names to the array used to hold the checkbox options labels.forEach(item => { checkboxLabelOptions.push({label: item.displayName, value: item.key}); }); // Set the checkbox group options as the label display names $w('#checkboxGroup2').options = checkboxLabelOptions; // Display the checkbox group element on the form $w('#checkboxGroup2').show(); } catch (error) { console.log(error) } } ``` ---