How to remove from one group and add to another one in the same API call?

  • 0
  • 1
  • Question
  • Updated 5 years ago
  • Answered
  • (Edited)
We are building a sign-up center where users can manage what mailing lists they are a part of.

The user simply checks the boxes of the mailing lists they want to be on, and unchecks the ones they no longer want.

I didn't find a function in the API that will update a member's group subscriptions to ONLY the group ids passed to it. It appears to me that a user must first be removed from the groups they don't want and added to the new groups they want.
Here's where I ran into problems.

Let's say I have a user subscribed to 5 mailing list groups. He unchecks 3 of them that he no longer wishes to receive.

I use this function to remove him from the groups he no longer wishes to have:
PUT /#account_id/members/#member_id/groups/remove

Then, immediately after that, I run this function to add the new groups he wants:
POST /#account_id/members/add

Here's the weird part, after running these, if I check his account, he is subscribed to the groups sent to the remove function.

I have verified that both functions work correctly if I run them in separate connection instances. For example, if I run a connection that only removes him from the groups, reload the page, and then run a connection that adds him to the new groups, everything works perfectly.

But if I run both back-to-back in the same api connection, the groups I send the first time somehow get applied to the 2nd function. I have triple-checked my code to ensure I'm not using any of the same variables.

Is it possible that emma is remembering the "group_ids" array from the first function and applying it to the 2nd, even though I send a new array? (The arrays are identical except for the "group_ids".)

I get this exact same behavior if I use
PUT /#account_id/members/#member_id/groups/remove
and then
PUT /#account_id/members/#member_id/groups
in sequence. It appears to use the group_ids sent the first time, and not the ones sent the 2nd time.

Additional information:
If I use this function to remove from ALL groups first, and then add the new groups, everything works perfectly: (note that I do not need to have "group_ids" to this first function).
DELETE /#account_id/members/#member_id/groups

If I use the functions in this order:
PUT /#account_id/members/#member_id/groups/remove
DELETE /#account_id/members/#member_id/groups
POST /#account_id/members/add
it still uses the groups sent to the very first function, which strengthens my suspicion.
Photo of David

David

  • 9 Posts
  • 0 Reply Likes

Posted 5 years ago

  • 0
  • 1
Photo of Tyler Scott

Tyler Scott, Employee

  • 805 Posts
  • 39 Reply Likes
Hey David! Thank you for the in-depth details and I’m going to reach out to one of my colleagues who has more of a greater knowledge on the API. I will be sure to give you a shout once I hear back from them.

Thanks!
Photo of David

David

  • 9 Posts
  • 0 Reply Likes
Thanks Tyler
Photo of David

David

  • 9 Posts
  • 0 Reply Likes
Just checking back in to see if they've had a chance to look into this yet.
Photo of Tyler Scott

Tyler Scott, Employee

  • 805 Posts
  • 39 Reply Likes
Hey David! I heard back from my colleague and reading through your post further it seems like you’ve found a process which is working to accomplish your goal. So honestly I say stick with what works! One thought we had was you could try adding the new groups first and then removing since it looks right now your process is removing and then adding.

Just a friendly reminder, utilizing the API is an option which we deem an expert feature which we don’t offer support for. We provide the documentation to give you some guidance and a great starting point, but for the nitty gritty we definitely leave that to the tech savvy folks such as yourself. 

Hopefully this helps though and please let me know if you have any questions.
Photo of David

David

  • 9 Posts
  • 0 Reply Likes
Hey Tyler! Thanks for all the help.
I understand that you guys don't officially provide support for the API. But it never hurts to ask, and you all have been super helpful with everything. Thanks so much!