getLocation( )
Retrieves a location.
Description
The getLocation()
function returns a Promise that resolves to the retrieved location.
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 of the location to retrieve.
Returns
Retrieved location.
Return Type:
NAME
TYPE
DESCRIPTION
Location ID.
Address.
Whether the location is archived. Archived locations can't be updated.
Note: Archiving a location
doesn't affect its status
.
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.
Whether this is the default location. There can only be one default location per site. The default location can't be archived.
Location description.
Email address.
Fax number.
Location type.
Supported values: BRANCH
, OFFICES
, RECEPTION
, HEADQUARTERS
.
Note: This field is currently not supported.
Location name.
Phone number.
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.
Location status.
Supported values: ACTIVE
, INACTIVE
.
Default: ACTIVE
Notes:
doesn't affect the location's status.
INACTIVE
status is currently not supported.
Timezone in America/New_York
format.
Was this helpful?
1import { locations } from 'wix-business-tools.v2';2import { elevate } from 'wix-auth';34/* Sample _id value: '0a965e36-4071-4df0-905b-75458817430a' */567export 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);1213 return myLocation;14 } catch (error) {15 console.error(error);16 // Handle the error17 }18}1920/* 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 */
1import { Permissions, webMethod } from 'wix-web-module';2import { locations } from 'wix-business-tools.v2';3import { elevate } from 'wix-auth';45/* Sample _id value: '0a965e36-4071-4df0-905b-75458817430a' */67export 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);1213 return myLocation;14 } catch (error) {15 console.error(error);16 // Handle the error17 }18});1920/* 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
This code uses the value of user's chosen location from a dropdown on the page and retrieves all of the location's information.
1/**************************************2 * Backend code - get-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 getLocationById = webMethod(Permissions.Anyone, async (locationId) => {10 try {11 const elevatedGetLocation = elevate(locations.getLocation);12 const myLocation = await elevatedGetLocation(locationId);1314 return myLocation;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 { getLocationById, listLocations } from 'backend/get-location.web';3940$w.onReady(async () => {41 await populateStoresDropdown();4243 $w('#getLocationBtn').onClick(async () => {44 const locationId = $w('#locationsDropdown').value;45 const myLocation = await getLocationById(locationId);4647 console.log('Here are the details of the location:', myLocation);48 $w('#locationDetails').text = myLocation;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