Search...
updateBusinessContact( )
Developer Preview
Updates a site's business contact information.
Description
The updateBusinessContact()
function returns a Promise that resolves when the site's contact information is updated.
Note:
- Only the fields included in the
fields
parameter will be updated, even if they are included in thebusinessContact
parameter.
Admin Method
This function requires elevated permissions to run. This function is not universal and runs only on the backend.
Syntax
function updateBusinessContact(businessContact: BusinessContactData, fields: Array<string>): Promise<void>
updateBusinessContact Parameters
NAME
TYPE
DESCRIPTION
businessContact
BusinessContactData
The site's business contact information.
fields
Array<
string
>The properties of businessContact
to be updated. Properties not explicitly specified here are ignored. Properties included here but excluded from businessContact
are cleared.
Returns
Return Type:
Promise<
void
>Was this helpful?
Update Business Contact (dashboard page code)
This example useselevate()
, which enables site visitors to call functions without the required permissions. Exercise caution when usingelevate()
to prevent security vulnerabilities.
Copy Code
1import { siteProperties } from 'wix-business-tools.v2';2import { elevate } from 'wix-auth';34/* Sample businessContact value:5 * {6 * address: {7 * apartmentNumber: '',8 * city: 'New York',9 * coordinates: {10 * latitude: 40.7128,11 * longitude: -74.006012 * },13 * country: 'US',14 * googleFormattedAddress: '123 Broadway, New York, NY 10001',15 * hint: {16 * placement: 'BEFORE',17 * text: 'On the corner - front entrance on 5th Avenue'18 * },19 * isPhysical: true,20 * state: 'NY',21 * street: 'Broadway',22 * streetNumber: '123',23 * zip: '10001'24 * },25 * email: 'mainaddress@example.com',26 * fax: '011-1-212-555-6789',27 * phone: '212-555-1234'28 * }29 *30 * Sample fields value: ['address', 'email', 'fax', 'phone']31 */3233export async function myUpdateBusinessContactFunction(businessContact, fields) {34 try {35 const elevatedUpdateBusinessContact = elevate(siteProperties.updateBusinessContact);36 await elevatedUpdateBusinessContact(businessContact, fields);3738 console.log('Successfully updated business contact');39 return true;40 } catch (error) {41 console.error(error);42 // Handle the error43 }44}4546/* Promise resolves to void */47
Update Business Contact (export from backend code)
This example useselevate()
, which enables site visitors to call functions without the required permissions. Exercise caution when usingelevate()
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';45/* Sample businessContact value:6 * {7 * address: {8 * apartmentNumber: '',9 * city: 'New York',10 * coordinates: {11 * latitude: 40.7128,12 * longitude: -74.006013 * },14 * country: 'US',15 * googleFormattedAddress: '123 Broadway, New York, NY 10001',16 * hint: {17 * placement: 'BEFORE',18 * text: 'On the corner - front entrance on 5th Avenue'19 * },20 * isPhysical: true,21 * state: 'NY',22 * street: 'Broadway',23 * streetNumber: '123',24 * zip: '10001'25 * },26 * email: 'mainaddress@example.com',27 * fax: '011-1-212-555-6789',28 * phone: '212-555-1234'29 * }30 *31 * Sample fields value: ['address', 'email', 'fax', 'phone']32 */3334export const myUpdateBusinessContactFunction = webMethod(Permissions.Anyone, async (businessContact, fields) => {35 try {36 const elevatedUpdateBusinessContact = elevate(siteProperties.updateBusinessContact);37 await elevatedUpdateBusinessContact(businessContact, fields);3839 console.log('Successfully updated business contact');40 return true;41 } catch (error) {42 console.error(error);43 // Handle the error44 }45});4647/* Promise resolves to void */48
Update email of business contact
This example useselevate()
, which enables site visitors to call functions without the required permissions. Exercise caution when usingelevate()
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';45/* Sample businessContact value:6 * {7 * email: 'mainaddress@example.com'8 * }9 *10 * Sample fields value: ['email']11 */1213export const myUpdateBusinessContactFunction = webMethod(Permissions.Anyone, async (businessContact, fields) => {14 try {15 const elevatedUpdateBusinessContact = elevate(siteProperties.updateBusinessContact);16 await elevatedUpdateBusinessContact(businessContact, fields);1718 console.log('Successfully updated business contact');19 return true;20 } catch (error) {21 console.error(error);22 // Handle the error23 }24});2526/* Promise resolves to void */
updateBusinessContact() for only specific fields
This code is an example of a webpage where the user updates the business' contact details. 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-contact.web.js *3 ************************************************/4import { Permissions, webMethod } from 'wix-web-module';5import { siteProperties } from 'wix-business-tools.v2';6import { elevate } from 'wix-auth';78export const contactDetailsUpdate = webMethod(Permissions.Anyone, async (businessContact, fields) => {9 try {10 const elevatedUpdateBusinessContact = elevate(siteProperties.updateBusinessContact);11 await elevatedUpdateBusinessContact(businessContact, fields);1213 console.log('Success! Contact Details Updated');14 return true;15 } catch (error) {16 console.error(error);17 throw new Error(error);18 }19});202122/*************23 * Page code *24 ************/2526import { contactDetailsUpdate } from 'backend/update-business-contact.web';2728$w.onReady(() => {29 $w('#submit').onClick(async () => {30 const paramDetails = getParamDetails();3132 if (!paramDetails.checkedFields.length) {33 $w('#changeAFieldsMsg').show();34 setTimeout(() => {35 $w('#changeAFieldsMsg').hide();36 }, 10000);37 } else {38 const isUpdated = await contactDetailsUpdate(paramDetails.updateDetails, paramDetails.checkedFields);3940 if (isUpdated) {41 console.log('Business Contact successfully updated');42 $w('#successfulUpdateMsg').show();43 setTimeout(() => {44 $w('#successfulUpdateMsg').hide();45 }, 10000);46 }47 }48 });49});5051function getParamDetails() {52 const checkedFields = [];53 const updateDetails = {}54 if ($w('#address').value.length) {55 checkedFields.push('address');56 updateDetails.address = $w('#address').value;57 }58 if ($w('#email').value.length) {59 checkedFields.push('email');60 updateDetails.email = $w('#email').value;61 }62 if ($w('#fax').value.length) {63 checkedFields.push('fax');64 updateDetails.fax = $w('#fax').value;65 }66 if ($w('#phone').value.length) {67 checkedFields.push('phone');68 updateDetails.phone = $w('#phone').value;69 }7071 return {updateDetails, checkedFields};72}73