I’ve been trying to use the new wix crm backend code to update contact by passing the contact id for a logged in user.
https://www.wix.com/velo/reference/wix-crm-backend/contacts-obj/updatecontact
Console errors show as the following after trying out various things.
"jsonPayload":{
"message":"Error: Error: Unable to handle the request. Contact the site administrator or view site monitoring logs for more information. "
}
//Another error showing up
jsonPayload":{
"message":"["message: ''\ndetails:\n applicationError:\n description: Forbidden\n code: FORBIDDEN\n data: {}"]"
}
Code is as follows below:
/*************
* Page code *
*************/
import wixUsers from 'wix-users';
import { overwriteContactInfo } from 'backend/contacts';
const contactId = wixUsers.currentUser.id;
console.log(contactId);
const updatedContactInfo = {
name: {
first: "Annie",
last: "New Name"
}
};
overwriteContactInfo(contactId, updatedContactInfo)
.then((updatedContact) => {
return updatedContact;
console.log(updatedContact);
})
.catch((error) => {
console.error(error);
});
/*******************************
* Backend code - contacts.jsw *
*******************************/
import { contacts } from 'wix-crm-backend';
export async function overwriteContactInfo(contactId, updatedContactInfo) {
// Get the contact's last revision number
const myContact = await contacts.getContact(contactId);
const contactIdentifiers = {
contactId: contactId,
revision: myContact.revision
};
const options = {
allowDuplicates: false,
"suppressAuth": true,
"suppressHooks": true
};
return await contacts.updateContact(contactIdentifiers, updatedContactInfo, options);
}
Can someone pls guide me as to what I am doing wrong???