I’m trying to use the following backend code to update the current user’s custom contact fields. This runs perfectly when I am logged in with my owner account, but all other accounts fail to update the custom fields. I thought setting “SuppressAuth” to “true” would allow this, but that doesn’t seem to help. As always, any advice appreciated.
import { contacts } from ‘wix-crm-backend’;
export async function overwriteContactInfo(contactId, updatedContactInfo) {
console.log(contactId);
const GetContactOptions = {
suppressAuth: true
};
const myContact = await contacts.getContact(contactId, GetContactOptions);
const contactIdentifiers = {
contactId: contactId,
revision: myContact.revision
};
const options = {
allowDuplicates: false,
suppressAuth: true
};
return await contacts.updateContact(contactIdentifiers, updatedContactInfo, options);
I also tried using the elevate function and ran into the same issue. The code works flawlessly for the owner account, but fails for all other accounts. Any help is greatly appreciated.
import { contacts } from ‘wix-crm-backend’;
import * as wixAuth from ‘wix-auth’;
export async function overwriteContactInfo(contactId, updatedContactInfo,options) {
const elevatedGetContact = wixAuth.elevate(contacts.getContact);
const elevatedUpdateContact = wixAuth.elevate(contacts.updateContact);
console.log(contactId);
// Get the contact’s last revision number
// const GetContactOptions = {
// suppressAuth: true
//};
const myContact = await elevatedGetContact(contactId);
const contactIdentifiers = {
contactId: contactId,
revision: myContact.revision
};
//const options = {
// allowDuplicates: false,
// suppressAuth: true
//};
return await elevatedUpdateContact(contactIdentifiers, updatedContactInfo);
}
Turns out the original code works correctly and my issue was burried in the front end as I wasn’t calling the backend code correctly. Hopefully someone gets something out of this. lol