> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # Method name: updateLocation(_id: string, location: UpdateLocation) # Method package: wixBusinessToolsV2 # Method menu location: wixBusinessToolsV2 --> locations --> updateLocation # Method Link: https://dev.wix.com/docs/velo/apis/wix-business-tools-v2/locations/update-location.md # Method Description: Overrides an existing location. > **Note:** Currently, it isn't possible to partially update a location. Therefore, you'll need to pass the full location object in the body of the call. # Method Code Examples: *** Note: do not assume any prop names or enum values other than the ones in the example. ## Update a location's details (dashboard page code) ```javascript import { locations } from 'wix-business-tools.v2'; import { elevate } from 'wix-auth'; /* Sample _id value: '4ae3bbc8-fb78-4eb7-8bc5-1fec19c7dbfc' * * Sample location value: * { * address: { * city: 'Roma', * country: 'IT', * formatted: 'Via Roma 123, 00100 Roma', * location: { * latitude: 41.9028, * longitude: 12.4964 * }, * postalCode: '00100', * streetAddress: { * apt: '', * name: 'Via Roma', * number: '123' * }, * subdivision: 'IT-RM' * }, * businessSchedule: { * periods: [ * { * closeDay: 'SATURDAY', * closeTime: '24:00', * openDay: 'MONDAY', * openTime: '00:00' * } * ], * specialHourPeriod: [ * { * comment: 'Half price in the lead up to Christmas!', * endDate: '2023-12-24T23:59:00Z', * isClosed: false, * startDate: '2023-12-01T00:00:00Z' * } * ] * }, * description: 'Our store in Rome is open 24/6!', * email: '24.6.rome@example.com', * fax: '+39 06 1234 5679', * name: 'Rome 24/6', * phone: '+39 06 1234 5678', * status: 'ACTIVE', * timeZone: 'Europe/Rome' * } */ export async function myCreateLocationFunction(_id, location) { try { const elevatedCreateLocation = elevate(locations.createLocation); const updatedLocation = await elevatedCreateLocation(_id, location); console.log('Location details have been successfully updated:', updatedLocation); return updatedLocation; } catch (error) { console.error(error); // Handle the error } } /* Promise resolves to: * { * "_id": "4ae3bbc8-fb78-4eb7-8bc5-1fec19c7dbfc" * "address": { * "city": "Roma", * "country": "IT", * "formatted": "Via Roma 123, 00100 Roma", * "location": { * "latitude": 41.9028, * "longitude": 12.4964 * }, * "postalCode": "00100", * "streetAddress": { * "apt": "", * "name": "Via Roma", * "number": "123" * }, * "subdivision": 'IT-RM' * }, * "archived": false, * "businessSchedule": { * "periods": [ * { * "closeDay": "MONDAY", * "closeTime": "00:00", * "openDay": "SATURDAY", * "openTime": "24:00" * } * ], * "specialHourPeriod": [ * { * "comment": "Half price in the lead up to Christmas!", * "endDate": "2023-12-24T23:59:00Z", * "isClosed": false, * "startDate": "2023-12-01T00:00:00Z" * } * ] * }, * "default": false, * "description": "Our store in Rome is open 24/6!", * "email": "24.6.rome@example.com", * "fax": "+39 06 1234 5679", * "name": "Rome 24/6", * "phone": "+39 06 1234 5678", * "revision": "2", * "status": "ACTIVE", * "timeZone": "Europe/Rome" * } */ ``` ## Update a location's details (export from backend code) ```javascript import { Permissions, webMethod } from 'wix-web-module'; import { locations } from 'wix-business-tools.v2'; import { elevate } from 'wix-auth'; /* Sample _id value: '4ae3bbc8-fb78-4eb7-8bc5-1fec19c7dbfc' * * Sample location value: * { * address: { * city: 'Roma', * country: 'IT', * formatted: 'Via Roma 123, 00100 Roma', * location: { * latitude: 41.9028, * longitude: 12.4964 * }, * postalCode: '00100', * streetAddress: { * apt: '', * name: 'Via Roma', * number: '123' * }, * subdivision: 'IT-RM' * }, * businessSchedule: { * periods: [ * { * closeDay: 'SATURDAY', * closeTime: '24:00', * openDay: 'MONDAY', * openTime: '00:00' * } * ], * specialHourPeriod: [ * { * comment: 'Half price in the lead up to Christmas!', * endDate: '2023-12-24T23:59:00Z', * isClosed: false, * startDate: '2023-12-01T00:00:00Z' * } * ] * }, * description: 'Our store in Rome is open 24/6!', * email: '24.6.rome@example.com', * fax: '+39 06 1234 5679', * name: 'Rome 24/6', * phone: '+39 06 1234 5678', * status: 'ACTIVE', * timeZone: 'Europe/Rome' * } */ export const myCreateLocationFunction = webMethod(Permissions.Anyone, async (_id, location) => { try { const elevatedCreateLocation = elevate(locations.createLocation); const updatedLocation = await elevatedCreateLocation(_id, location); console.log('Location details have been successfully updated:', updatedLocation); return updatedLocation; } catch (error) { console.error(error); // Handle the error } }); /* Promise resolves to: * { * "_id": "4ae3bbc8-fb78-4eb7-8bc5-1fec19c7dbfc" * "address": { * "city": "Roma", * "country": "IT", * "formatted": "Via Roma 123, 00100 Roma", * "location": { * "latitude": 41.9028, * "longitude": 12.4964 * }, * "postalCode": "00100", * "streetAddress": { * "apt": "", * "name": "Via Roma", * "number": "123" * }, * "subdivision": 'IT-RM' * }, * "archived": false, * "businessSchedule": { * "periods": [ * { * "closeDay": "MONDAY", * "closeTime": "00:00", * "openDay": "SATURDAY", * "openTime": "24:00" * } * ], * "specialHourPeriod": [ * { * "comment": "Half price in the lead up to Christmas!", * "endDate": "2023-12-24T23:59:00Z", * "isClosed": false, * "startDate": "2023-12-01T00:00:00Z" * } * ] * }, * "default": false, * "description": "Our store in Rome is open 24/6!", * "email": "24.6.rome@example.com", * "fax": "+39 06 1234 5679", * "name": "Rome 24/6", * "phone": "+39 06 1234 5678", * "revision": "2", * "status": "ACTIVE", * "timeZone": "Europe/Rome" * } */ ``` ## Overwrite a location's data ```javascript /***************************************** * Backend code - update-location.web.js * ****************************************/ import { Permissions, webMethod } from 'wix-web-module'; import { locations } from 'wix-business-tools.v2'; import { elevate } from 'wix-auth'; export const updateLocation = webMethod(Permissions.Anyone, async (locationId, location) => { try { const elevatedUpdateLocation = elevate(locations.updateLocation); const updatedLocation = await elevatedUpdateLocation(locationId, location); return updatedLocation; } catch (error) { console.error(error); throw new Error(error); } }); export const listLocations = webMethod(Permissions.Anyone, async () => { try { const elevatedListLocations = elevate(locations.listLocations); const results = await elevatedListLocations(); return results.locations; } catch (error) { console.error(error); throw new Error(error); } }); export const getLocationById = webMethod(Permissions.Anyone, async (locationId) => { try { const elevatedGetLocation = elevate(locations.getLocation); const myLocation = await elevatedGetLocation(locationId); return myLocation; } catch (error) { console.error(error); throw new Error(error); } }); /************* * Page code * ************/ import { updateLocation, listLocations, getLocationById } from 'backend/update-location.web'; $w.onReady(async () => { await populateStoresDropdown(); $w('#update').onClick(async () => { const locationId = $w('#locationsDropdown').value; const currentLocationValues = await getLocationById(locationId); const location = { name: $w('#newName').value, address: { streetAddress: { number: $w('#streetNumber').value, name: $w('#streetName').value }, city: $w('#city').value, postalCode: $w('#postalCode').value, }, timeZone: $w('#timeZone').value, description: $w('#description').value, email: $w('#email').value, phone: $w('#phone').value, // Must use the current revision value revision: currentLocationValues.revision }; const updatedLocation = await updateLocation(locationId, location); console.log('Location details have been successfully updated to the following:\n', updatedLocation); $w('#updateSuccessMsg').show(); }); }); async function populateStoresDropdown() { const locations = await listLocations(); const dropdownOptions = locations.map((location) => { return { label: location.name, value: location._id }; }); $w('#locationsDropdown').options = dropdownOptions; }; ``` ## Partially update a location's data without overwriting other properties ```javascript /***************************************** * Backend code - update-location.web.js * ****************************************/ import { Permissions, webMethod } from 'wix-web-module'; import { locations } from 'wix-business-tools.v2'; import { elevate } from 'wix-auth'; export const updateLocation = webMethod(Permissions.Anyone, async (locationId, location) => { try { const elevatedUpdateLocation = elevate(locations.updateLocation); const updatedLocation = await elevatedUpdateLocation(locationId, location); return updatedLocation; } catch (error) { console.error(error); throw new Error(error); } }); export const listLocations = webMethod(Permissions.Anyone, async () => { try { const elevatedListLocations = elevate(locations.listLocations); const results = await elevatedListLocations(); return results.locations; } catch (error) { console.error(error); throw new Error(error); } }); export const getLocationById = webMethod(Permissions.Anyone, async (locationId) => { try { const elevatedGetLocation = elevate(locations.getLocation); const myLocation = await elevatedGetLocation(locationId); return myLocation; } catch (error) { console.error(error); throw new Error(error); } }); /************* * Page code * ************/ import { updateLocation, listLocations, getLocationById } from 'backend/update-location.web'; $w.onReady(async () => { await populateStoresDropdown(); $w('#update').onClick(async () => { // set location to current value and only change relevant properties' values const locationId = $w('#locationsDropdown').value; const location = await getLocationById(locationId); location.email = $w('#email').value; location.phone = $w('#phone').value; const updatedLocation = await updateLocation(locationId, location); console.log('Location details have been successfully updated to the following:\n', updatedLocation); $w('#updateSuccessMsg').show(); }); }); async function populateStoresDropdown() { const locations = await listLocations(); const dropdownOptions = locations.map((location) => { return { label: location.name, value: location._id }; }); $w('#locationsDropdown').options = dropdownOptions; } ``` ---