> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> 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`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - 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: queryLocations()

# Method package: wixBusinessToolsV2

# Method menu location: wixBusinessToolsV2 --> locations --> queryLocations

# Method Link: https://dev.wix.com/docs/velo/apis/wix-business-tools-v2/locations/query-locations.md

# Method Description:

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`.


|PROPERTY	|SUPPORTED FILTERS & SORTING	
|:---:|:---:|
|`_id`|[`eq()`](/locations-query-builder/eq),[`ne()`](/locations-query-builder/ne),[`exists()`](/locations-query-builder/exists),[`in()`](/locations-query-builder/in),[`hasSome()`](/locations-query-builder/has-some),[`startsWith()`](/locations-query-builder/starts-with)|
|`name`|[`eq()`](/locations-query-builder/eq),[`ne()`](/locations-query-builder/ne),[`exists()`](/locations-query-builder/exists),[`in()`](/locations-query-builder/in),[`hasSome()`](/locations-query-builder/has-some),[`startsWith()`](/locations-query-builder/starts-with)|
|`description`|[`eq()`](/locations-query-builder/eq),[`ne()`](/locations-query-builder/ne),[`exists()`](/locations-query-builder/exists),[`in()`](/locations-query-builder/in),[`hasSome()`](/locations-query-builder/has-some),[`startsWith()`](/locations-query-builder/starts-with)|
|`default`|[`eq()`](/locations-query-builder/eq),[`ne()`](/locations-query-builder/ne),[`exists()`](/locations-query-builder/exists),[`in()`](/locations-query-builder/in),[`hasSome()`](/locations-query-builder/has-some)|
|`status`|[`eq()`](/locations-query-builder/eq),[`ne()`](/locations-query-builder/ne),[`exists()`](/locations-query-builder/exists),[`in()`](/locations-query-builder/in),[`hasSome()`](/locations-query-builder/has-some)|
|`locationType`|[`eq()`](/locations-query-builder/eq),[`ne()`](/locations-query-builder/ne),[`exists()`](/locations-query-builder/exists),[`in()`](/locations-query-builder/in),[`hasSome()`](/locations-query-builder/has-some)|
|`fax`|[`eq()`](/locations-query-builder/eq),[`ne()`](/locations-query-builder/ne),[`exists()`](/locations-query-builder/exists),[`in()`](/locations-query-builder/in),[`hasSome()`](/locations-query-builder/has-some),[`startsWith()`](/locations-query-builder/starts-with)|
|`timeZone`|[`eq()`](/locations-query-builder/eq),[`ne()`](/locations-query-builder/ne),[`exists()`](/locations-query-builder/exists),[`in()`](/locations-query-builder/in),[`hasSome()`](/locations-query-builder/has-some),[`startsWith()`](/locations-query-builder/starts-with)|
|`email`|[`eq()`](/locations-query-builder/eq),[`ne()`](/locations-query-builder/ne),[`exists()`](/locations-query-builder/exists),[`in()`](/locations-query-builder/in),[`hasSome()`](/locations-query-builder/has-some),[`startsWith()`](/locations-query-builder/starts-with)|
|`phone`|[`eq()`](/locations-query-builder/eq),[`ne()`](/locations-query-builder/ne),[`exists()`](/locations-query-builder/exists),[`in()`](/locations-query-builder/in),[`hasSome()`](/locations-query-builder/has-some),[`startsWith()`](/locations-query-builder/starts-with)|
|`address.country`|[`eq()`](/locations-query-builder/eq),[`ne()`](/locations-query-builder/ne),[`exists()`](/locations-query-builder/exists),[`in()`](/locations-query-builder/in),[`hasSome()`](/locations-query-builder/has-some),[`startsWith()`](/locations-query-builder/starts-with)|
|`address.subdivision`|[`eq()`](/locations-query-builder/eq),[`ne()`](/locations-query-builder/ne),[`exists()`](/locations-query-builder/exists),[`in()`](/locations-query-builder/in),[`hasSome()`](/locations-query-builder/has-some),[`startsWith()`](/locations-query-builder/starts-with)|
|`address.city`|[`eq()`](/locations-query-builder/eq),[`ne()`](/locations-query-builder/ne),[`exists()`](/locations-query-builder/exists),[`in()`](/locations-query-builder/in),[`hasSome()`](/locations-query-builder/has-some),[`startsWith()`](/locations-query-builder/starts-with)|
|`address.postalCode`|[`eq()`](/locations-query-builder/eq),[`ne()`](/locations-query-builder/ne),[`exists()`](/locations-query-builder/exists),[`in()`](/locations-query-builder/in),[`hasSome()`](/locations-query-builder/has-some),[`startsWith()`](/locations-query-builder/starts-with)|
|`address.streetAddress.number`|[`eq()`](/locations-query-builder/eq),[`ne()`](/locations-query-builder/ne),[`exists()`](/locations-query-builder/exists),[`in()`](/locations-query-builder/in),[`hasSome()`](/locations-query-builder/has-some),[`startsWith()`](/locations-query-builder/starts-with)|
|`address.streetAddress.name`|[`eq()`](/locations-query-builder/eq),[`ne()`](/locations-query-builder/ne),[`exists()`](/locations-query-builder/exists),[`in()`](/locations-query-builder/in),[`hasSome()`](/locations-query-builder/has-some),[`startsWith()`](/locations-query-builder/starts-with)|
|`address.streetAddress.apt`|[`eq()`](/locations-query-builder/eq),[`ne()`](/locations-query-builder/ne),[`exists()`](/locations-query-builder/exists),[`in()`](/locations-query-builder/in),[`hasSome()`](/locations-query-builder/has-some),[`startsWith()`](/locations-query-builder/starts-with)|
|`address.formattedAddress`|[`eq()`](/locations-query-builder/eq),[`ne()`](/locations-query-builder/ne),[`exists()`](/locations-query-builder/exists),[`in()`](/locations-query-builder/in),[`hasSome()`](/locations-query-builder/has-some),[`startsWith()`](/locations-query-builder/starts-with)|
|`address.hint`|[`eq()`](/locations-query-builder/eq),[`ne()`](/locations-query-builder/ne),[`exists()`](/locations-query-builder/exists),[`in()`](/locations-query-builder/in),[`hasSome()`](/locations-query-builder/has-some),[`startsWith()`](/locations-query-builder/starts-with)|
|`address.geocode.latitude`|[`eq()`](/locations-query-builder/eq),[`ne()`](/locations-query-builder/ne),[`exists()`](/locations-query-builder/exists),[`in()`](/locations-query-builder/in),[`hasSome()`](/locations-query-builder/has-some),[`lt()`](/locations-query-builder/lt),[`le()`](/locations-query-builder/le),[`gt()`](/locations-query-builder/gt),[`ge()`](/locations-query-builder/ge)|
|`address.geocode.longitude`|[`eq()`](/locations-query-builder/eq),[`ne()`](/locations-query-builder/ne),[`exists()`](/locations-query-builder/exists),[`in()`](/locations-query-builder/in),[`hasSome()`](/locations-query-builder/has-some),[`lt()`](/locations-query-builder/lt),[`le()`](/locations-query-builder/le),[`gt()`](/locations-query-builder/gt),[`ge()`](/locations-query-builder/ge)|
|`businessSchedule.periods.openDay`|[`eq()`](/locations-query-builder/eq),[`ne()`](/locations-query-builder/ne),[`exists()`](/locations-query-builder/exists),[`in()`](/locations-query-builder/in),[`hasSome()`](/locations-query-builder/has-some)|
|`businessSchedule.periods.openTime`|[`eq()`](/locations-query-builder/eq),[`ne()`](/locations-query-builder/ne),[`exists()`](/locations-query-builder/exists),[`in()`](/locations-query-builder/in),[`hasSome()`](/locations-query-builder/has-some),[`startsWith()`](/locations-query-builder/starts-with)|
|`businessSchedule.periods.closeDay`|[`eq()`](/locations-query-builder/eq),[`ne()`](/locations-query-builder/ne),[`exists()`](/locations-query-builder/exists),[`in()`](/locations-query-builder/in),[`hasSome()`](/locations-query-builder/has-some)|
|`businessSchedule.periods.closeTime`|[`eq()`](/locations-query-builder/eq),[`ne()`](/locations-query-builder/ne),[`exists()`](/locations-query-builder/exists),[`in()`](/locations-query-builder/in),[`hasSome()`](/locations-query-builder/has-some),[`startsWith()`](/locations-query-builder/starts-with)|
|`businessSchedule.specialHourPeriod.startDate`|[`eq()`](/locations-query-builder/eq),[`ne()`](/locations-query-builder/ne),[`exists()`](/locations-query-builder/exists),[`in()`](/locations-query-builder/in),[`hasSome()`](/locations-query-builder/has-some),[`startsWith()`](/locations-query-builder/starts-with)|
|`businessSchedule.specialHourPeriod.endDate`|[`eq()`](/locations-query-builder/eq),[`ne()`](/locations-query-builder/ne),[`exists()`](/locations-query-builder/exists),[`in()`](/locations-query-builder/in),[`hasSome()`](/locations-query-builder/has-some),[`startsWith()`](/locations-query-builder/starts-with)|
|`businessSchedule.specialHourPeriod.isClosed`|[`eq()`](/locations-query-builder/eq),[`ne()`](/locations-query-builder/ne),[`exists()`](/locations-query-builder/exists),[`in()`](/locations-query-builder/in),[`hasSome()`](/locations-query-builder/has-some)|
|`businessSchedule.specialHourPeriod.comment`|[`eq()`](/locations-query-builder/eq),[`ne()`](/locations-query-builder/ne),[`exists()`](/locations-query-builder/exists),[`in()`](/locations-query-builder/in),[`hasSome()`](/locations-query-builder/has-some),[`startsWith()`](/locations-query-builder/starts-with)|
|`revision`|[`eq()`](/locations-query-builder/eq),[`ne()`](/locations-query-builder/ne),[`exists()`](/locations-query-builder/exists),[`in()`](/locations-query-builder/in),[`hasSome()`](/locations-query-builder/has-some),[`lt()`](/locations-query-builder/lt),[`le()`](/locations-query-builder/le),[`gt()`](/locations-query-builder/gt),[`ge()`](/locations-query-builder/ge)|
|`archived`|[`eq()`](/locations-query-builder/eq),[`ne()`](/locations-query-builder/ne),[`exists()`](/locations-query-builder/exists),[`in()`](/locations-query-builder/in),[`hasSome()`](/locations-query-builder/has-some)|



# Method Code Examples:

*** Note: do not assume any prop names or enum values other than the ones in the example.

## Retrieve all locations (dashboard page code) 

```javascript
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"
 *   }
 * ]
 */

```

## Retrieve all locations (export from backend code) 

```javascript
import { Permissions, webMethod } from 'wix-web-module';
import { locations } from 'wix-business-tools.v2';
import { elevate } from 'wix-auth';

export const myQueryLocationsFunction = webMethod(Permissions.Anyone, async () => {
  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"
 *   }
 * ]
 */

```

## Retrieve locations using multiple filters 

```javascript
/****************************************
 * Backend code - query-location.web.js *
 ***************************************/

import { Permissions, webMethod } from 'wix-web-module';
import { locations } from 'wix-business-tools.v2';
import { elevate } from 'wix-auth';

export const queryLocationsByNameStart = webMethod(Permissions.Anyone, async (searchInput) => {
  try {
    const elevatedQueryLocations = elevate(locations.queryLocations)
    const result = await elevatedQueryLocations()
      .startsWith('name', searchInput)
      .eq('status', 'ACTIVE')
      .find();

    return result.items;
  } catch (error) {
    console.error(error);
    throw new Error(error);
  }
});


/*************
 * Page code *
 ************/

import { queryLocationsByNameStart } from 'backend/query-location.web';

$w.onReady(() => {
  $w('#getBranchLocations').onClick(async () => {
    const searchName = $w('#search').value;
    const locations = await queryLocationsByNameStart(searchName);

    const dropdownOptions = locations.map((location) => {
      return {
        label: location.name,
        value: location._id
      }
    });
    $w('#locationsDropdown').options = dropdownOptions;
  });
});

```

---