Update data in WixMembers by code

Question:
Hello everbody,

I created my own account page, linked to WixMembers.
I would like members to be able to modify their personal data (picture, telephone number, email, address, etc.).

It’s OK for finding the member, and extract “RecupNomClt” & “RecupMailClt”, but I have an error when requesting Update (In the example below, I would like to modify the profile photo.

Error msg in the console : “Uncaught (in promise) R: WDE0004: Failed to save [[object Object]] into [Members/PrivateMembersData].
Items must be JavaScript objects.”

Thanks for your help

Product:
Wix Editor

My Code below :

$w(‘#MAJProfil’).onClick((event) => {

// RECHERCHER LE CLIENT
return wixData.query(‘Members/PrivateMembersData’)
.eq(“_id”, $w(‘#UserID’).value)
.find()
.then(async (results) => {
//1°/ MODIFIER LA PHOTO DU CLIENT
console.log("Effectuer la recherche à partir de l’ID: "+ “(” + $w(‘#UserID’).value + “)”)

   const RecupNomClt = results.items.map(item => item.name)
     const RecupMailClt= results.items.map(item => item.loginEmail)

    console.log("Nom : " + RecupNomClt)
    console.log("Mail : " + RecupMailClt)
  
  const MAJPictClt = results.items.map(item => ({ ...item, picture: $w('#Photoprofil').src}))
   
  await wixData.update('Members/PrivateMembersData', MAJPictClt);
  
  console.log(results); >  

});

})

Hi, user3373 !!

First, I believe there might be an issue with the permissions required to modify data in the Private Members Data collection. Since the data in this collection is protected based on the permissions settings, you would need to temporarily relax the permissions in the backend to execute the update() method. (I’m not entirely sure if it’s actually possible to edit this collection’s data—apologies, but please verify this yourself…)

As for the error you’re encountering, it’s likely because the update() method only accepts a single object as its argument, but you’re passing an array. Since map() returns an array, MAJPictClt becomes an array, which is the root cause of the issue. :raised_hands:

Hi
For me you have to use updateMember( )
https://dev.wix.com/docs/velo/api-reference/wix-members-backend/members/update-member

and other function depending of what you want update.

Best regards,

That’s probably the right answer! :raised_hands:

Hi

thanks for your answers. I’ll try with “Update Member” and tell you .

Hello

I didin’t succeed. But not very important for the moment, my site works fine. il will see later for this (modify the picture of a logged member)

thanks