Search.../

getLocation( )

Developer Preview

Retrieves a location.

Description

The getLocation() function returns a Promise that resolves to the retrieved location.

Admin Method

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

Syntax

function getLocation(_id: string): Promise<Location>

getLocation Parameters

NAME
TYPE
DESCRIPTION
_id
string

ID of the location to retrieve.

Returns

Retrieved location.

Return Type:

Promise<
Location
>
NAME
TYPE
DESCRIPTION
_id
string

Location ID.

address
Address

Address.

archived
boolean

Whether the location is archived. Archived locations can't be updated.

Note: Archiving a location doesn't affect its status.

businessSchedule
BusinessSchedule

Business schedule. Array of weekly recurring time periods when the location is open for business. Limited to 100 time periods.

Note: Not supported by Wix Bookings.

default
boolean

Whether this is the default location. There can only be one default location per site. The default location can't be archived.

description
string

Location description.

email
string

Email address.

fax
string

Fax number.

locationType
string

Location type.

Supported values: BRANCH, OFFICES, RECEPTION, HEADQUARTERS.

Note: This field is currently not supported.

name
string

Location name.

phone
string

Phone number.

revision
string

Revision number, which increments by 1 each time the location is updated. To prevent conflicting changes, the existing revision must be used when updating a location.

status
string

Location status.

Supported values: ACTIVE, INACTIVE.

Default: ACTIVE

Notes:

doesn't affect the location's status.

  • INACTIVE status is currently not supported.
timeZone
string

Timezone in America/New_York format.

Was this helpful?

Get a location (dashboard page code)

Copy Code
1import { locations } from 'wix-business-tools.v2';
2import { elevate } from 'wix-auth';
3
4/* Sample _id value: '0a965e36-4071-4df0-905b-75458817430a' */
5
6
7export async function myGetLocationFunction(_id) {
8 try {
9 const elevatedGetLocation = elevate(locations.getLocation);
10 const myLocation = await elevatedGetLocation(_id);
11 console.log('Here are the details of the location:', myLocation);
12
13 return myLocation;
14 } catch (error) {
15 console.error(error);
16 // Handle the error
17 }
18}
19
20/* Promise resolves to:
21 * {
22 * "_id": "0a965e36-4071-4df0-905b-75458817430a",
23 * "address": {
24 * "streetAddress": {
25 * "apt": "",
26 * "name": "Calle Miguel Hidalgo",
27 * "number": "15"
28 * },
29 * "city": "La Reforma",
30 * "postalCode": "22000"
31 * },
32 * "archived": false,
33 * "default": false,
34 * "description": "Our brand new, budget store in the heart of Mexico City!",
35 * "email": "store@example.com",
36 * "phone": "+52 55 1234 5678",
37 * "name": "Mexico Store",
38 * "revision": "2",
39 * "status": "ACTIVE",
40 * "timeZone": "America/Mexico_City"
41 * }
42 */
Get a location (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';
4
5/* Sample _id value: '0a965e36-4071-4df0-905b-75458817430a' */
6
7export const myGetLocationFunction = webMethod(Permissions.Anyone, async (_id) => {
8 try {
9 const elevatedGetLocation = elevate(locations.getLocation);
10 const myLocation = await elevatedGetLocation(_id);
11 console.log('Here are the details of the location:', myLocation);
12
13 return myLocation;
14 } catch (error) {
15 console.error(error);
16 // Handle the error
17 }
18});
19
20/* Promise resolves to:
21 * {
22 * "_id": "0a965e36-4071-4df0-905b-75458817430a",
23 * "address": {
24 * "streetAddress": {
25 * "apt": "",
26 * "name": "Calle Miguel Hidalgo",
27 * "number": "15"
28 * },
29 * "city": "La Reforma",
30 * "postalCode": "22000"
31 * },
32 * "archived": false,
33 * "default": false,
34 * "description": "Our brand new, budget store in the heart of Mexico City!",
35 * "email": "store@example.com",
36 * "phone": "+52 55 1234 5678",
37 * "name": "Mexico Store",
38 * "revision": "2",
39 * "status": "ACTIVE",
40 * "timeZone": "America/Mexico_City"
41 * }
42 */
43
Get a location's properties

This code uses the value of user's chosen location from a dropdown on the page and retrieves all of the location's information.

Copy Code
1/**************************************
2 * Backend code - get-location.web.js *
3 *************************************/
4
5import { Permissions, webMethod } from 'wix-web-module';
6import { locations } from 'wix-business-tools.v2';
7import { elevate } from 'wix-auth';
8
9export const getLocationById = webMethod(Permissions.Anyone, async (locationId) => {
10 try {
11 const elevatedGetLocation = elevate(locations.getLocation);
12 const myLocation = await elevatedGetLocation(locationId);
13
14 return myLocation;
15 } catch (error) {
16 console.error(error);
17 throw new Error(error);
18 }
19});
20
21export const listLocations = webMethod(Permissions.Anyone, async () => {
22 try {
23 const elevatedListLocations = elevate(locations.listLocations);
24 const results = await elevatedListLocations();
25
26 return results.locations;
27 } catch (error) {
28 console.error(error);
29 throw new Error(error);
30 }
31});
32
33
34/*************
35 * Page code *
36 ************/
37
38import { getLocationById, listLocations } from 'backend/get-location.web';
39
40$w.onReady(async () => {
41 await populateStoresDropdown();
42
43 $w('#getLocationBtn').onClick(async () => {
44 const locationId = $w('#locationsDropdown').value;
45 const myLocation = await getLocationById(locationId);
46
47 console.log('Here are the details of the location:', myLocation);
48 $w('#locationDetails').text = myLocation;
49 });
50});
51
52async function populateStoresDropdown() {
53 const locations = await listLocations();
54 const dropdownOptions = locations.map((location) => {
55 return {
56 label: location.name,
57 value: location._id
58 }
59 });
60
61 $w('#locationsDropdown').options = dropdownOptions;
62}
63