Search...
listLocations( )
Developer Preview
Retrieves a list of locations.
Description
Retrieves a list of up to 1,000 locations, given the provided filters, sorting, and paging.
Admin Method
This function requires elevated permissions to run. This function is not universal and runs only on the backend.
Syntax
function listLocations(options: ListLocationsOptions): Promise<ListLocationsResponse>
listLocations Parameters
NAME
TYPE
DESCRIPTION
options
Optional
ListLocationsOptions
Options to use when retrieving a list of locations.
Returns
Return Type:
Promise<
ListLocationsResponse
>NAME
TYPE
DESCRIPTION
locations
Array<
Location
>Retrieved locations.
pagingMetadata
PagingMetadata
Paging info.
Was this helpful?
List all locations (dashboard page code)
Copy Code
1import { locations } from 'wix-business-tools.v2';2import { elevate } from 'wix-auth';34export async function myGetLocationFunction(_id) {5 try {6 const elevatedGetLocation = elevate(locations.getLocation);7 const myLocations = await elevatedGetLocation(_id);8 console.log('Locations:', myLocations);910 return myLocations;11 } catch (error) {12 console.error(error);13 // Handle the error14 }15}1617/* Promise resolves to:18 * {19 * "locations": [20 * {21 * "_id": "6a7a7356-a122-4de6-943c-3ea9e66f0d0a",22 * "address": {23 * "city": "Costa Mesa",24 * "country": "US",25 * "formatted": "Location1980, Placentia Avenue, Costa Mesa, CA, USA",26 * "location": {27 * "latitude": 33.6463497,28 * "longitude": -117.93186729 * },30 * "postalCode": "92627"31 * "streetAddress": {32 * "apt": "",33 * "name": "Placentia Avenue",34 * "number": "1980"35 * },36 * "subdivision": "CA",37 * },38 * "archived": false,39 * "businessSchedule": {40 * "periods": [],41 * "specialHourPeriod": []42 * },43 * "default": true,44 * "email": "",45 * "fax": "",46 * "name": "Costa Mesa Store",47 * "phone": "",48 * "revision": "1",49 * "status": "ACTIVE",50 * "timeZone": "America/Los_Angeles"51 * },52 * {53 * "_id": "6a0c5611-0610-4fc2-9eda-a5614ffaf141",54 * "address": {55 * "city": "Kingston",56 * "country": "CA",57 * "formatted": "222, Stuart Street, Kingston, ON, Canada",58 * "location": {59 * "latitude": 44.2236494,60 * "longitude": -76.499221661 * },62 * "postalCode": "K7L 2W1"63 * "streetAddress": {64 * "apt": "",65 * "name": "Stuart Street",66 * "number": "222"67 * },68 * "subdivision": "ON",69 * },70 * "archived": false,71 * "businessSchedule": {72 * "periods": [],73 * "specialHourPeriod": []74 * },75 * "default": false,76 * "email": "",77 * "fax": "",78 * "name": "Kingston Store",79 * "phone": "",80 * "revision": "1",81 * "status": "ACTIVE",82 * "timeZone": "America/Los_Angeles"83 * }84 * ],85 * "pagingMetadata": {86 * "count": 2,87 * "hasNext": false88 * }89 * }90 */91
List all locations (export from backend code)
Copy Code
1import { Permissions, webMethod } from 'wix-web-module';2import { locations } from 'wix-business-tools.v2';3import { elevate } from 'wix-auth';45export const myListLocationsFunction = webMethod(Permissions.Anyone, async () => {6 try {7 const elevatedListLocations = elevate(locations.listLocations);8 const myLocations = await elevatedListLocations();9 console.log('Locations:', myLocations);1011 return myLocations;12 } catch (error) {13 console.error(error);14 // Handle the error15 }16});1718/* Promise resolves to:19 * {20 * "locations": [21 * {22 * "_id": "6a7a7356-a122-4de6-943c-3ea9e66f0d0a",23 * "address": {24 * "city": "Costa Mesa",25 * "country": "US",26 * "formatted": "Location1980, Placentia Avenue, Costa Mesa, CA, USA",27 * "location": {28 * "latitude": 33.6463497,29 * "longitude": -117.93186730 * },31 * "postalCode": "92627"32 * "streetAddress": {33 * "apt": "",34 * "name": "Placentia Avenue",35 * "number": "1980"36 * },37 * "subdivision": "CA",38 * },39 * "archived": false,40 * "businessSchedule": {41 * "periods": [],42 * "specialHourPeriod": []43 * },44 * "default": true,45 * "email": "",46 * "fax": "",47 * "name": "Costa Mesa Store",48 * "phone": "",49 * "revision": "1",50 * "status": "ACTIVE",51 * "timeZone": "America/Los_Angeles"52 * },53 * {54 * "_id": "6a0c5611-0610-4fc2-9eda-a5614ffaf141",55 * "address": {56 * "city": "Kingston",57 * "country": "CA",58 * "formatted": "222, Stuart Street, Kingston, ON, Canada",59 * "location": {60 * "latitude": 44.2236494,61 * "longitude": -76.499221662 * },63 * "postalCode": "K7L 2W1"64 * "streetAddress": {65 * "apt": "",66 * "name": "Stuart Street",67 * "number": "222"68 * },69 * "subdivision": "ON",70 * },71 * "archived": false,72 * "businessSchedule": {73 * "periods": [],74 * "specialHourPeriod": []75 * },76 * "default": false,77 * "email": "",78 * "fax": "",79 * "name": "Kingston Store",80 * "phone": "",81 * "revision": "1",82 * "status": "ACTIVE",83 * "timeZone": "America/Los_Angeles"84 * }85 * ],86 * "pagingMetadata": {87 * "count": 2,88 * "hasNext": false89 * }90 * }91 */92
List all locations
Copy Code
1import { Permissions, webMethod } from 'wix-web-module';2import { locations } from 'wix-business-tools.v2';3import { elevate } from 'wix-auth';45/* Sample options value:6 * {7 * includeArchived: true,8 * paging: {9 * limit: 3,10 * offset: 011 * },12 * sort: {13 * fieldName: 'name',14 * order: 'ASC'15 * }16 * }17 */1819export const myListLocationsFunction = webMethod(Permissions.Anyone, async (options) => {20 try {21 const elevatedListLocations = elevate(locations.listLocations);22 const myLocations = await elevatedListLocations(options);23 console.log('Locations:', myLocations);2425 return myLocations;26 } catch (error) {27 console.error(error);28 // Handle the error29 }30});3132/* Promise resolves to:33 * {34 * "locations": [35 * {36 * "_id": "6a0c5611-0610-4fc2-9eda-a5614ffaf141",37 * "address": {38 * "city": "Buenos Aires",39 * "country": "AR",40 * "formatted": "456, Example Street, Buenos Aires, Argentina",41 * "location": {42 * "latitude": -34.6037,43 * "longitude": -58.381644 * },45 * "postalCode": "C1234",46 * "streetAddress": {47 * "apt": "",48 * "name": "Example Street",49 * "number": "456"50 * },51 * "subdivision": ""52 * },53 * "archived": false,54 * "businessSchedule": {55 * "periods": [],56 * "specialHourPeriod": []57 * },58 * "default": false,59 * "email": "",60 * "fax": "",61 * "name": "Buenos Aires Store",62 * "phone": "",63 * "revision": "1",64 * "status": "ACTIVE",65 * "timeZone": "America/Argentina/Buenos_Aires"66 * },67 * {68 * "_id": "6a0c5611-0610-4fc2-9eda-a5614ffaf142",69 * "address": {70 * "city": "Paris",71 * "country": "FR",72 * "formatted": "789, Rue de l'Exemple, Paris, France",73 * "location": {74 * "latitude": 48.8566,75 * "longitude": 2.352276 * },77 * "postalCode": "75001",78 * "streetAddress": {79 * "apt": "",80 * "name": "Rue de l'Exemple",81 * "number": "789"82 * },83 * "subdivision": ""84 * },85 * "archived": false,86 * "businessSchedule": {87 * "periods": [],88 * "specialHourPeriod": []89 * },90 * "default": false,91 * "email": "",92 * "fax": "",93 * "name": "Paris Store",94 * "phone": "",95 * "revision": "1",96 * "status": "ACTIVE",97 * "timeZone": "Europe/Paris"98 * },99 * {100 * "_id": "6a7a7356-a122-4de6-943c-3ea9e66f0d0a",101 * "address": {102 * "city": "Vienna",103 * "country": "AT",104 * "formatted": "Examplestraße 123, Vienna, Austria",105 * "location": {106 * "latitude": 48.8566,107 * "longitude": 2.3522108 * },109 * "postalCode": "12345",110 * "streetAddress": {111 * "apt": "",112 * "name": "Examplestraße",113 * "number": "123"114 * },115 * "subdivision": ""116 * },117 * "archived": false,118 * "businessSchedule": {119 * "periods": [],120 * "specialHourPeriod": []121 * },122 * "default": true,123 * "email": "",124 * "fax": "",125 * "name": "Vienna Store",126 * "phone": "",127 * "revision": "1",128 * "status": "ACTIVE",129 * "timeZone": "Europe/Vienna"130 * }131 * ],132 * "pagingMetadata": {133 * "count": 3,134 * "hasNext": true135 * }136 * }137 */138
Archive a location
This code uses the value of user's chosen location from a dropdown on the page and archives it.
Copy Code
1/******************************************2 * Backend code - archive-location.web.js *3 *****************************************/45import { Permissions, webMethod } from 'wix-web-module';6import { locations } from 'wix-business-tools.v2';7import { elevate } from 'wix-auth';89export const archiveLocationById = webMethod(Permissions.Anyone, async (locationId) => {10 try {11 const elevatedArchiveLocation = elevate(locations.archiveLocation);12 const archivedLocation = await elevatedArchiveLocation(locationId);1314 return archivedLocation;15 } catch (error) {16 console.error(error);17 throw new Error(error);18 }19});2021export const listLocations = webMethod(Permissions.Anyone, async () => {22 try {23 const elevatedListLocations = elevate(locations.listLocations);24 const results = await elevatedListLocations();2526 return results.locations;27 } catch (error) {28 console.error(error);29 throw new Error(error);30 }31});323334/*************35 * Page code *36 ************/3738import { archiveLocationById, listLocations } from 'backend/archive-location.web';3940$w.onReady(async () => {41 await populateStoresDropdown();4243 $w('#archiveLocationBtn').onClick(async () => {44 const locationId = $w('#locationsDropdown').value;45 const archivedLocation = await archiveLocationById(locationId);4647 console.log('The following location has been archived', archivedLocation);48 $w('#archivedMessage').show();49 });50});5152async function populateStoresDropdown() {53 const locations = await listLocations();54 const dropdownOptions = locations.map((location) => {55 return {56 label: location.name,57 value: location._id58 }59 });6061 $w('#locationsDropdown').options = dropdownOptions;62}63