Search.../

queryLocations( )

Developer Preview

Creates a query to retrieve a list of locations.

Description

The queryLocations() function builds a query to retrieve a list of up to 1,000 locations and returns a LocationsQueryBuilder object.

The returned object contains the query definition which is typically used to run the query using the find() function.

You can refine the query by chaining LocationsQueryBuilder functions onto the query. LocationsQueryBuilder functions enable you to sort, filter, and control the results that queryLocations() returns. The functions that are chained to queryLocations() are applied in the order they are called.

queryLocations() runs with the following LocationsQueryBuilder defaults that you can override:

  • skip: 0
  • limit: 50

The following QueryLocationsBuilder functions are supported for the queryLocations() function. For a full description of the Locations object, see the object returned for the items property in LocationsQueryResult.

PROPERTYSUPPORTED FILTERS & SORTING
_ideq(),ne(),exists(),in(),hasSome(),startsWith()
nameeq(),ne(),exists(),in(),hasSome(),startsWith()
descriptioneq(),ne(),exists(),in(),hasSome(),startsWith()
defaulteq(),ne(),exists(),in(),hasSome()
statuseq(),ne(),exists(),in(),hasSome()
locationTypeeq(),ne(),exists(),in(),hasSome()
faxeq(),ne(),exists(),in(),hasSome(),startsWith()
timeZoneeq(),ne(),exists(),in(),hasSome(),startsWith()
emaileq(),ne(),exists(),in(),hasSome(),startsWith()
phoneeq(),ne(),exists(),in(),hasSome(),startsWith()
address.countryeq(),ne(),exists(),in(),hasSome(),startsWith()
address.subdivisioneq(),ne(),exists(),in(),hasSome(),startsWith()
address.cityeq(),ne(),exists(),in(),hasSome(),startsWith()
address.postalCodeeq(),ne(),exists(),in(),hasSome(),startsWith()
address.streetAddress.numbereq(),ne(),exists(),in(),hasSome(),startsWith()
address.streetAddress.nameeq(),ne(),exists(),in(),hasSome(),startsWith()
address.streetAddress.apteq(),ne(),exists(),in(),hasSome(),startsWith()
address.formattedAddresseq(),ne(),exists(),in(),hasSome(),startsWith()
address.hinteq(),ne(),exists(),in(),hasSome(),startsWith()
address.geocode.latitudeeq(),ne(),exists(),in(),hasSome(),lt(),le(),gt(),ge()
address.geocode.longitudeeq(),ne(),exists(),in(),hasSome(),lt(),le(),gt(),ge()
businessSchedule.periods.openDayeq(),ne(),exists(),in(),hasSome()
businessSchedule.periods.openTimeeq(),ne(),exists(),in(),hasSome(),startsWith()
businessSchedule.periods.closeDayeq(),ne(),exists(),in(),hasSome()
businessSchedule.periods.closeTimeeq(),ne(),exists(),in(),hasSome(),startsWith()
businessSchedule.specialHourPeriod.startDateeq(),ne(),exists(),in(),hasSome(),startsWith()
businessSchedule.specialHourPeriod.endDateeq(),ne(),exists(),in(),hasSome(),startsWith()
businessSchedule.specialHourPeriod.isClosedeq(),ne(),exists(),in(),hasSome()
businessSchedule.specialHourPeriod.commenteq(),ne(),exists(),in(),hasSome(),startsWith()
revisioneq(),ne(),exists(),in(),hasSome(),lt(),le(),gt(),ge()
archivedeq(),ne(),exists(),in(),hasSome()
Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function queryLocations(): LocationsQueryBuilder

queryLocations Parameters

This function does not take any parameters.

Returns

Was this helpful?

Retrieve all locations

Copy Code
1import { locations } from 'wix-business-tools.v2';
2import { elevate } from 'wix-auth';
3
4export async function myQueryLocationsFunction() {
5 try {
6 const elevatedQueryLocations = elevate(locations.queryLocations);
7 const myLocations = await elevatedQueryLocations().find();
8 const items = myLocations.items;
9 console.log('Locations:', items);
10
11 return items;
12 } catch (error) {
13 console.error(error);
14 // Handle the error
15 }
16}
17
18/* Returns items:
19 * [
20 * {
21 * "_id": "5c6e81a4-5270-4f66-9688-49d1fd9153ef",
22 * "address": {
23 * "city": "Amsterdam",
24 * "country": "NL",
25 * "formatted": "CityHub, Bellamystraat, Amsterdam, Netherlands",
26 * "location": {
27 * "latitude": 52.3672879,
28 * "longitude": 4.867098899999998
29 * },
30 * "postalCode": "1053 BE",
31 * "streetAddress": {
32 * "apt": "",
33 * "name": "Bellamystraat",
34 * "number": "3"
35 * },
36 * "subdivision": "NH"
37 * },
38 * "archived": false,
39 * "businessSchedule": {
40 * "periods": [],
41 * "specialHourPeriod": []
42 * },
43 * "default": false,
44 * "email": "amsterdam.store@example.com",
45 * "fax": "+31 20 765 4321",
46 * "name": "Bellamystraat",
47 * "phone": "+31 20 123 4567",
48 * "status": "ACTIVE",
49 * "timeZone": "Europe/Amsterdam",
50 * "revision": "1"
51 * },
52 * {
53 * "_id": "e3b2c1ff-2bf2-41da-9f4a-983c8799074a",
54 * "address": {
55 * "city": "Brisbane City",
56 * "country": "AU",
57 * "formatted": "Arise, Margaret Street, Brisbane City QLD, Australia",
58 * "location": {
59 * "latitude": -27.4718535,
60 * "longitude": 153.0288312
61 * },
62 * "postalCode": "4000",
63 * "streetAddress": {
64 * "apt": "",
65 * "name": "Margaret Street",
66 * "number": "222"
67 * },
68 * "subdivision": "QLD"
69 * },
70 * "archived": false,
71 * "businessSchedule": {
72 * "periods": [],
73 * "specialHourPeriod": []
74 * },
75 * "default": false,
76 * "email": "australia.store@examp;e.com",
77 * "fax": "+61 2 9876 5432",
78 * "name": "Margaret Street",
79 * "phone": "+61 2 1234 5678",
80 * "revision": "1",
81 * "status": "ACTIVE",
82 * "timeZone": "Australia/Brisbane"
83 * }
84 * ]
85 */
Retrieve locations using multiple filters

This is an example of a page where user searches for locations, and the search results populates a dropdown. The query only returns active locations.

Copy Code
1/*************************************
2 * Backend code - query-location.jsw *
3 ************************************/
4
5import { locations } from 'wix-business-tools.v2';
6import { elevate } from 'wix-auth';
7
8export async function queryLocationsByNameStart(searchInput) {
9 try {
10 const elevatedQueryLocations = elevate(locations.queryLocations)
11 const result = await elevatedQueryLocations()
12 .startsWith('name', searchInput)
13 .eq('status', 'ACTIVE')
14 .find();
15
16 return result.items;
17 } catch (error) {
18 console.error(error);
19 throw new Error(error);
20 }
21}
22
23
24/*************
25 * Page code *
26 ************/
27
28import { queryLocationsByNameStart } from 'backend/query-location';
29
30$w.onReady(() => {
31 $w('#getBranchLocations').onClick(async () => {
32 const searchName = $w('#search').value;
33 const locations = await queryLocationsByNameStart(searchName);
34
35 const dropdownOptions = locations.map((location) => {
36 return {
37 label: location.name,
38 value: location._id
39 }
40 });
41 $w('#locationsDropdown').options = dropdownOptions;
42 });
43});