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

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
6export async function myGetLocationFunction(_id) {
7 try {
8 const elevatedGetLocation = elevate(locations.getLocation);
9 const myLocation = await elevatedGetLocation(_id);
10 console.log('Here are the details of the location:', myLocation);
11
12 return myLocation;
13 } catch (error) {
14 console.error(error);
15 // Handle the error
16 }
17}
18
19/* Promise resolves to:
20 * {
21 * "_id": "0a965e36-4071-4df0-905b-75458817430a",
22 * "address": {
23 * "streetAddress": {
24 * "apt": "",
25 * "name": "Calle Miguel Hidalgo",
26 * "number": "15"
27 * },
28 * "city": "La Reforma",
29 * "postalCode": "22000"
30 * },
31 * "archived": false,
32 * "default": false,
33 * "description": "Our brand new, budget store in the heart of Mexico City!",
34 * "email": "store@example.com",
35 * "phone": "+52 55 1234 5678",
36 * "name": "Mexico Store",
37 * "revision": "2",
38 * "status": "ACTIVE",
39 * "timeZone": "America/Mexico_City"
40 * }
41 */
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.jsw *
3 **********************************/
4
5import { locations } from 'wix-business-tools.v2';
6import { elevate } from 'wix-auth';
7
8export async function getLocationById(locationId) {
9 try {
10 const elevatedGetLocation = elevate(locations.getLocation);
11 const myLocation = await elevatedGetLocation(locationId);
12
13 return myLocation;
14 } catch (error) {
15 console.error(error);
16 throw new Error(error);
17 }
18}
19
20export async function listLocations() {
21 try {
22 const elevatedListLocations = elevate(locations.listLocations);
23 const results = await elevatedListLocations();
24
25 return results.locations;
26 } catch (error) {
27 console.error(error);
28 throw new Error(error);
29 }
30}
31
32
33/*************
34 * Page code *
35 ************/
36
37import { getLocationById, listLocations } from 'backend/get-location';
38
39$w.onReady(async () => {
40 await populateStoresDropdown();
41
42 $w('#getLocationBtn').onClick(async () => {
43 const locationId = $w('#locationsDropdown').value;
44 const myLocation = await getLocationById(locationId);
45
46 console.log('Here are the details of the location:', myLocation);
47 $w('#locationDetails').text = myLocation;
48 });
49});
50
51async function populateStoresDropdown() {
52 const locations = await listLocations();
53 const dropdownOptions = locations.map((location) => {
54 return {
55 label: location.name,
56 value: location._id
57 }
58 });
59
60 $w('#locationsDropdown').options = dropdownOptions;
61}