# API Filter users by emails, including secondary emails

**URL:** <https://meta.discourse.org/t/api-filter-users-by-emails-including-secondary-emails/296910>\
**Category:** Development\
**Tags:** rest-api\
**Created:** [February 27, 2024, 3:03pm UTC](https://meta.discourse.org/t/api-filter-users-by-emails-including-secondary-emails/296910 "2024-02-27T15:03:20Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![oca](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/oca/32/156060_2.png) [@oca](https://meta.discourse.org/u/oca)\
**Post date:** [February 27, 2024, 3:03pm UTC](https://meta.discourse.org/t/api-filter-users-by-emails-including-secondary-emails/296910/1 "2024-02-27T15:03:20Z")

</div>

Hello,

I would like to match users from a list of email addresses coming from an other app, in order to add all the users to one group, and remove members that are not in the . I’ve got a script doing that from the API.

The removing part is easy. For each member, I extract all their emails with:  
` get(/u/{username}/emails.json)`  
and I try to match each one against the list. If there is none, the member is excluded.

The including one is trickier. For each email address, I want to see if there is a user with that address. If there is, I add it to the group. If there is not, I don’t want to send an invite. I use the command:  
`get(/admin/users/list/all.json?email={email})`  
but this command returns a list of users with that address as primary, an not the ones with that address as _secondary_, nor _unconfirmed\_emails_, nor _associated\_accounts_. Is there a way to filter from every possible email addresses, or should I export the list of all users and do that by hand externally ? I would prefer doing it internally so there would be less risks of data leaks.

Thanks !

---

_[View the full topic](https://meta.discourse.org/t/api-filter-users-by-emails-including-secondary-emails/296910)._
