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() ,ne() |
key | eq() ,ne() ,in() |
displayName | eq() ,ne() ,in() ,startsWith() ,ascending() ,descending() |
labelType | eq() |
_createdDate | eq() ,ne() ,gt() ,lt() ,ge() ,le() ,ascending() ,descending() |
_updatedDate | eq() ,ne() ,gt() ,lt() ,ge() ,le() ,ascending() ,descending() |
This function requires elevated permissions and runs only on the backend and on dashboard pages.
function queryLabels(options: QueryLabelsOptions): LabelsQueryBuilder;
Language options.
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"
* }
* ]
*/
There are 6 errors with this status code.
This method may also return standard errors. Learn more about standard Wix errors.