Search.../

updateBusinessProfile( )

Developer Preview

Updates a site's business profile information.

Description

The updateBusinessProfile() function returns a Promise that resolves when the site's business profile information is updated.

Note:

  • Only the fields included in the fields parameter are updated, even if they are included in the businessProfile parameter.
Admin Method

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

Syntax

function updateBusinessProfile(businessProfile: BusinessProfileData, fields: Array<string>): Promise<void>

updateBusinessProfile Parameters

NAME
TYPE
DESCRIPTION
businessProfile
BusinessProfileData

The site's business profile.

fields
Array<
string
>

The properties of businessProfile to be updated. Properties not explicitly specified here are ignored. Properties included here but excluded from businessProfile are cleared.

Returns

Return Type:

Promise<
void
>

Was this helpful?

Update Business Profile (dashboard page code)
This example uses elevate(), which enables site visitors to call functions without the required permissions. Exercise caution when using elevate() to prevent security vulnerabilities.

Copy Code
1import { siteProperties } from 'wix-business-tools.v2';
2import { elevate } from 'wix-auth';
3
4/* Sample businessProfile value:
5 * {
6 * description: 'Whatever the occasion, we have what you need.',
7 * logo: 'a8a52b_bf5596e614d8484e9f1d429ac256e1ad~mv2.jpeg'
8 * }
9 *
10 * Sample fields value: ['description', 'logo']
11 */
12
13export async function myUpdateBusinessProfileFunction(businessProfile, fields) {
14 try {
15 const elevatedUpdateBusinessProfile = elevate(siteProperties.updateBusinessProfile);
16 await elevatedUpdateBusinessProfile(businessProfile, fields);
17
18 console.log('Successfully updated business profile');
19 return true;
20 } catch (error) {
21 console.error(error);
22 // Handle the error
23 }
24}
25
26/* Promise resolves to void */
27
Update Business Profile (export from backend code)
This example uses elevate(), which enables site visitors to call functions without the required permissions. Exercise caution when using elevate() to prevent security vulnerabilities.

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { siteProperties } from 'wix-business-tools.v2';
3import { elevate } from 'wix-auth';
4
5/* Sample businessProfile value:
6 * {
7 * description: 'Whatever the occasion, we have what you need.',
8 * logo: 'a8a52b_bf5596e614d8484e9f1d429ac256e1ad~mv2.jpeg'
9 * }
10 *
11 * Sample fields value: ['description', 'logo']
12 */
13
14export const myUpdateBusinessProfileFunction = webMethod(Permissions.Anyone, async (businessProfile, fields) => {
15 try {
16 const elevatedUpdateBusinessProfile = elevate(siteProperties.updateBusinessProfile);
17 await elevatedUpdateBusinessProfile(businessProfile, fields);
18
19 console.log('Successfully updated business profile');
20 return true;
21 } catch (error) {
22 console.error(error);
23 // Handle the error
24 }
25});
26
27/* Promise resolves to void */
28
Update description of business profile
This example uses elevate(), which enables site visitors to call functions without the required permissions. Exercise caution when using elevate() to prevent security vulnerabilities.

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { siteProperties } from 'wix-business-tools.v2';
3import { elevate } from 'wix-auth';
4
5/* Sample businessProfile value:
6 * {
7 * description: 'We have what you need, whatever the occasion.'
8 * }
9 *
10 * Sample fields value: ['description']
11 */
12
13export const myUpdateBusinessProfileFunction = webMethod(Permissions.Anyone, async (businessProfile, fields) => {
14 try {
15 const elevatedUpdateBusinessProfile = elevate(siteProperties.updateBusinessProfile);
16 await elevatedUpdateBusinessProfile(businessProfile, fields);
17
18 console.log('Successfully updated business profile');
19 return true;
20 } catch (error) {
21 console.error(error);
22 // Handle the error
23 }
24});
25
26/* Promise resolves to void */
updateBusinessProfile() for only specific fields

This code is an example of a webpage where the user updates the business' description or logo. If they don't enter text for a specific field, it won't overwrite. Access to this page would be given only to managers.

Copy Code
1/*************************************************
2 * Backend code - update-business-profile.web.js *
3 ************************************************/
4import { Permissions, webMethod } from 'wix-web-module';
5import { siteProperties } from 'wix-business-tools.v2';
6import { elevate } from 'wix-auth';
7
8export const profileDetailsUpdate = webMethod(Permissions.Anyone, async (businessProfile, fields) => {
9 try {
10 const elevatedUpdateBusinessProfile = elevate(siteProperties.updateBusinessProfile);
11 await elevatedUpdateBusinessProfile(businessProfile, fields);
12
13 console.log('Success! Profile Details Updated');
14 return true;
15 } catch (error) {
16 console.error(error);
17 throw new Error(error);
18 }
19});
20
21
22/*************
23 * Page code *
24 ************/
25
26import { profileDetailsUpdate } from 'backend/update-business-profile.web';
27
28$w.onReady(() => {
29 $w('#submit').onClick(async () => {
30 const paramDetails = getParamDetails();
31
32 if (!paramDetails.checkedFields.length) {
33 $w('#changeAFieldsMsg').show();
34 setTimeout(() => {
35 $w('#changeAFieldsMsg').hide();
36 }, 10000);
37 } else {
38 const isUpdated = await profileDetailsUpdate(paramDetails.updateDetails, paramDetails.checkedFields);
39
40 if (isUpdated) {
41 console.log('Business Profile successfully updated');
42 $w('#successfulUpdateMsg').show();
43 setTimeout(() => {
44 $w('#successfulUpdateMsg').hide();
45 }, 10000);
46 }
47 }
48 });
49});
50
51function getParamDetails() {
52 const checkedFields = [];
53 const updateDetails = {};
54 if ($w('#description').value.length) {
55 checkedFields.push('description');
56 updateDetails.description = $w('#description').value;
57 }
58 if ($w('#logo').value.length) {
59 checkedFields.push('logo');
60 updateDetails.logo = $w('#logo').value;
61 }
62
63 return {updateDetails, checkedFields};
64}