Search.../

setDefaultLocation( )

Developer Preview

Sets a new default location.

Description

The setDefaultLocation() function returns a Promise that resolves to the new default location.

Notes:

  • There can be only one default location per site.
  • The setDefaultLocation() function changes the value of the default property of both the new and old default locations objects.
  • The 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 setDefaultLocation(_id: string): Promise<SetDefaultLocationResponse>

setDefaultLocation Parameters

NAME
TYPE
DESCRIPTION
_id
string

ID of the location to set as the default location.

Returns

Return Type:

Promise<
SetDefaultLocationResponse
>
NAME
TYPE
DESCRIPTION
location
Location

New default location.

Was this helpful?

Set the default 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 changeDefaultLocation(_id) {
7 try {
8 const elevatedSetDefaultLocation = elevate(locations.setDefaultLocation);
9 const myDefaultLocation = await elevatedSetDefaultLocation(_id);
10 console.log('Default location has been changed to:', myDefaultLocation);
11
12 return myDefaultLocation;
13 } catch (error) {
14 console.error(error);
15 // Handle the error
16 }
17}
18
19/* Promise resolves to:
20 * {
21 * location: {
22 * "_id": "0a965e36-4071-4df0-905b-75458817430a",
23 * "address": {
24 * "streetAddress": {
25 * "apt": "34",
26 * "name": "Musterstraße",
27 * "number": "5"
28 * },
29 * "city": "Berlin",
30 * "postalCode": "53782"
31 * },
32 * "archived": false,
33 * "default": true,
34 * "description": "Our brand new store in Germany",
35 * "email": "store@example.com",
36 * "name": "Germany Store",
37 * "phone": "0208 209 9087",
38 * "revision": "2",
39 * "status": "ACTIVE",
40 * "timeZone": "Europe/Berlin"
41 * }
42 * }
43 */