This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.
Creates a query to retrieve a list of locations.
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
.
function queryLocations(): LocationsQueryBuilder;
import { locations } from "wix-business-tools.v2";
import { elevate } from "wix-auth";
export async function myQueryLocationsFunction() {
try {
const elevatedQueryLocations = elevate(locations.queryLocations);
const myLocations = await elevatedQueryLocations().find();
const items = myLocations.items;
console.log("Locations:", items);
return items;
} catch (error) {
console.error(error);
// Handle the error
}
}
/* Returns items:
* [
* {
* "_id": "5c6e81a4-5270-4f66-9688-49d1fd9153ef",
* "address": {
* "city": "Amsterdam",
* "country": "NL",
* "formatted": "CityHub, Bellamystraat, Amsterdam, Netherlands",
* "location": {
* "latitude": 52.3672879,
* "longitude": 4.867098899999998
* },
* "postalCode": "1053 BE",
* "streetAddress": {
* "apt": "",
* "name": "Bellamystraat",
* "number": "3"
* },
* "subdivision": "NH"
* },
* "archived": false,
* "businessSchedule": {
* "periods": [],
* "specialHourPeriod": []
* },
* "default": false,
* "email": "amsterdam.store@example.com",
* "fax": "+31 20 765 4321",
* "name": "Bellamystraat",
* "phone": "+31 20 123 4567",
* "status": "ACTIVE",
* "timeZone": "Europe/Amsterdam",
* "revision": "1"
* },
* {
* "_id": "e3b2c1ff-2bf2-41da-9f4a-983c8799074a",
* "address": {
* "city": "Brisbane City",
* "country": "AU",
* "formatted": "Arise, Margaret Street, Brisbane City QLD, Australia",
* "location": {
* "latitude": -27.4718535,
* "longitude": 153.0288312
* },
* "postalCode": "4000",
* "streetAddress": {
* "apt": "",
* "name": "Margaret Street",
* "number": "222"
* },
* "subdivision": "QLD"
* },
* "archived": false,
* "businessSchedule": {
* "periods": [],
* "specialHourPeriod": []
* },
* "default": false,
* "email": "australia.store@examp;e.com",
* "fax": "+61 2 9876 5432",
* "name": "Margaret Street",
* "phone": "+61 2 1234 5678",
* "revision": "1",
* "status": "ACTIVE",
* "timeZone": "Australia/Brisbane"
* }
* ]
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.