Search.../

archiveLocation( )

Developer Preview

Archives a location.

Description

The archiveLocation() function returns a Promise that resolves to the archived location.

The archiveLocation() function changes a location's archived property to true.

Notes:

  • A location's status isn't affected by this function.
  • An archived location can't be updated.
  • It's currently not possible to unarchive locations.
  • A default location can't be archived.
Admin Method

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

Syntax

function archiveLocation(_id: string): Promise<ArchiveLocationResponse>

archiveLocation Parameters

NAME
TYPE
DESCRIPTION
_id
string

ID of the location to archive.

Returns

Return Type:

Promise<
ArchiveLocationResponse
>
NAME
TYPE
DESCRIPTION
location
Location

Archived location.

Was this helpful?

Archive 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 myArchiveLocationFunction(_id) {
7 try {
8 const elevatedArchiveLocation = elevate(locations.archiveLocation);
9 const archivedLocation = await elevatedArchiveLocation(_id);
10 console.log('Location has been archived:', archivedLocation);
11
12 return archivedLocation;
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": "New Road",
26 * "number": "12"
27 * },
28 * "city": "Kolkata",
29 * "postalCode": "70027"
30 * },
31 * "archived": true,
32 * "default": false,
33 * "description": "New store in India!",
34 * "email": "store@example.com",
35 * "name": "India Store",
36 * "phone": "0208 209 9087",
37 * "revision": "2",
38 * "status": "ACTIVE",
39 * "timeZone": "Asia/Calcutta",
40 * }
41 */
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.jsw *
3 **************************************/
4
5import { locations } from 'wix-business-tools.v2';
6import { elevate } from 'wix-auth';
7
8export async function archiveLocationById (locationId) {
9 try {
10 const elevatedArchiveLocation = elevate(locations.archiveLocation);
11 const archivedLocation = await elevatedArchiveLocation(locationId);
12
13 return archivedLocation;
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 { archiveLocationById, listLocations } from 'backend/archive-location';
38
39$w.onReady(async () => {
40 await populateStoresDropdown();
41
42 $w('#archiveLocationBtn').onClick(async () => {
43 const locationId = $w('#locationsDropdown').value;
44 const archivedLocation = await archiveLocationById(locationId);
45
46 console.log('The following location has been archived', archivedLocation);
47 $w('#archivedMessage').show();
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}