HELP with Wix Backend code returning Array(0)

Please help!!! I am trying to auto add new members to a default group. The permissions on this group are set to allow all members to add anyone to this group.

I created a backend function

export async function addMembersToGroup ( identifiers , options ) {
return members . addGroupMembers ( identifiers , options )
. then (( addedGroupMembers ) => {
return addedGroupMembers ;
})
. catch (( error ) => {
console . error ( error );
});
}

From my front end i am calling this function as
function addMemberIdToGroup ( memberId , groupId ) {
$w ( “#createProfileErrorLabel” ). text = "Adding member " + currentMemberId + " to groupID " + groupId ;
let addGroupIds = {
“groupId” : groupId ,
“memberIds” : [ memberId ]
};
let options = {
“suppressAuth” : true
};

 addMembersToGroup ( addGroupIds ,  options ) 
  . then (( result ) => { 
      console . log ( "Add member to groups" + result ); 
  }) 
  . catch (( err ) => { 
            console . log ( err ); 
        }); 

}

My front end gets an undefined object. I validated that my groupID and MemberID are correct.

I also tried running the backend method above in the JSW file run button and passing the JSON inputs. But i receive an Array(0) json response (SEE IMAGE ATTACHED )


instead of member data as mentioned in the Velo doc here https://www.wix.com/velo/reference/wix-groups-backend/members/addgroupmembers

The member does not get added to the group either. I am not sure what am i doing wrong. I have been stuck here since last 2 days. I would really appreciate any help or pointers. Thanks in advance.

@yisrael-wix - sorry to tag you but i have seen you have good solutions to a lot of wix velo code related problems. Wondering if you have encountered this issue and have a solution. Would really appreciate any help.

From my front end i am calling this function as …

Maybe this one…???

$w.onReady(async()=>{
	let memberId = "" //<---- generate here your Member-ID
	let groupId = ""	//<---- generate here your Group-ID

	let myWishedResults = await  addMemberIdToGroup(memberId, groupId);
	console.log(myWishedResults);
	//---------------------------------------------------
	$w("#createProfileErrorLabel").text = "Adding member "+ currentMemberId+" to groupID "+groupId;
	
});


function addMemberIdToGroup(memberId, groupId) {
	let addGroupIds = {"groupId" : groupId,  "memberIds" : [memberId]}
	let options = {"suppressAuth": true}

	addMembersToGroup(addGroupIds, options).then((result) => {
		console.log("Add member to groups"+result);
		return result
	}).catch((err) => {console.log(err);});
}

@russian-dima - thanks for your response. I tried your suggestion of calling this method in main with async and wait. It still returns undefined, this doesnt work.

The thing is running this method by clicking the run button on the backend also doesnt return anything. So am wondering if this api ever worked.

I really don’t want to reconstruct whole setup to be able to test it.
When you have the project directly in front of your eyes, it is much easier to DEBUG it.
If you want i can take a look directly on your project.
You will find my contact in my profile.

I just emailed you. Thanks.

Hey, in Wix Groups it’s not possible to add a member with private profile. Please, make sure that member you want to add is having a public profile. You can find more info here - https://support.wix.com/en/article/wix-groups-member-privacy-settings-for-groups.

Btw, there is an option you can enable to make all new sign-ups to have a public profile by default. Hope it helps :slight_smile:

@dnaumenko - Thank you so much! This works finally!!! Spent 3 days working on this. thank you. I wish someone updates the addedMemberGroup wix doc to mention this so others dont struggle with this.

One more thing i observed is to make your members join as “PUBLIC” by default you need to add Join the community field in your custom form and select it to yes by default apart from the setting the settings you mentioned above.

Thanks @russian-dima for your help with debugging, really appreciate it.