updateContact not updating

I am trying to use the recently released updateContact API to update the login email of a contact/site member. Here is my front end code:

export async function updateLogin_click(event) {
let currentEmail = $w(‘#currentLogin’).value;
let newEmail = $w(‘#newLogin’).value;
let findmember = await wixData.query(“Members/PrivateMembersData”)
.eq(“loginEmail”,currentEmail)
.find()
let firstItem = findmember.items[0];
console.log(firstItem.loginEmail, firstItem._id);
let contactID = firstItem._id;
let newlogin = await updateLoginEmail(contactID,newEmail);
}

And here the backend code:

import wixCrm from ‘wix-crm-backend’;

export function updateLoginEmail(contactId, newLogin) {
wixCrm.updateContact(contactId, {
“loginEmail”: newLogin
})
.then(()=>{
console.log(“login updated”);
})
}

The code appears to be working – the “login updated” message appears on the console – but the login email for the contact is not updated. The API documentation says that this field can be updated, but perhaps there is something special about the loginEmail field? I have tried this in both Preview and Live mode. Same result. Any one else tried this?

#updateContact wix-crm-backend

Won’t be much help here, however in your front end code try changing ContactID to ContactId in your last two lines.

In your backend code, try adding all of the code as you seem to not have the catch (err) at the end of your backend code from the API sample

UpdateContact() API sample:

import wixCrm from 'wix-crm-backend';

export function myBackendFunction(contactId, firstName, lastName, email, phone) {wixCrm.updateContact(contactId, {
"firstName": firstName,
"lastName": lastName,
"emails": [email],
"phones": [phone]
} )
.then( () => {
// contact has been updated
} )
.catch( (err) => {
// there was an error updating the contact
} );
}

Finally, as loginEmail is an option available in the ContactInfo then it should be able to be changed and updated as you want and as the new API notes state.

However, when you say you have tried it in both preview and live mode, I would just check that like a lot of Wix API’s, that it doesn’t work fully in any preview state and only in a live and published site.

Also, I would assume that you are setup as Admin on your site, so when you login you are logging in as Admin and not Site Member.

Therefore, I recommend trying the updateContact for the loginEmail on just a member and not your Admin account. You might have to setup a new member and then delete it when you are finished.

I just think that Admins might not be able to change our login emails through this method as Wix might only allow Admins to change their email on their Wix account.

Although the user role shouldn’t really make any difference to any email that is used to log into a website, however Wix never seem to make things simple, or as you have already stated, there might just be teething issues with it and there is a simple fix to all of this!

As we can now update Contact Info, then I would wish they would change this page about the actual Private Members Data dataset as they still state on this page that we can’t update any field and nor can we change the permissions of the dataset:

Anyways, hope you get this sorted and apologies I can’t be any more help to you.

Thanks for your reply. I am trying this on a regular member account, not an Admin account, so that should not be an issue. As for the sample code, I started with that, then moved to async, then went back to .then() format. In no case did the .catch() catch anything, but I did get the console.log from the .then() – which would imply that the promise resolved properly and the update should have taken place. Except… it didn’t. We’ll see if other weigh in on this one. Thanks again!

@davebogan98 Any solution for changing the login email via API? I notice the option isnt possible using the Member Info page that wix provides, so wonder if that page is outdated or the API was released without allowing the permissions yet.