# Search for users by email domain

**URL:** <https://devforum.okta.com/t/search-for-users-by-email-domain/27351>\
**Category:** API\
**Tags:** api\
**Created:** [March 20, 2024, 6:31pm UTC](https://devforum.okta.com/t/search-for-users-by-email-domain/27351 "2024-03-20T18:31:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![figandbones](https://avatars.discourse-cdn.com/v4/letter/f/bbe5ce/32.png) [@figandbones](https://devforum.okta.com/u/figandbones)\
**Post date:** [March 20, 2024, 6:31pm UTC](https://devforum.okta.com/t/search-for-users-by-email-domain/27351/1 "2024-03-20T18:31:12Z")

</div>

I’m writing code for a feature that allows us to change the email domain for all users given old and new domain names.  
So I would need to search the directory for all users having the old email domain.  
If I do a search like:  
`/api/v1/users?search=profile.email+sw+%22test%22`  
I get all users whose email starts with ‘test’  
But if I search with endsWith:  
`/api/v1/users?search=profile.email+ew+%22example.com%22`  
I get this error:

```auto
{
  "errorCode": "E0000031",
  "errorSummary": "Invalid search criteria.",
  "errorLink": "E0000031",
  "errorId": "oaeBre_Q4s6SHWeKFK6WCo4Og",
  "errorCauses": [
    {
      "errorSummary": "Invalid search syntax."
    }
  ]
}

```

I expect that the directory will eventually be quite large, so I don’t want to pull all users.  
How can I search users by email domain?

---

<div class="post-metadata">

**Author:** ![erik](https://avatars.discourse-cdn.com/v4/letter/e/b5ac83/32.png) [@erik](https://devforum.okta.com/u/erik)\
**Post date:** [March 21, 2024, 7:01am UTC](https://devforum.okta.com/t/search-for-users-by-email-domain/27351/2 "2024-03-21T07:01:13Z")

</div>

Hello,

`ew` is only available for the System Log API

> **[Core Okta API | Okta Developer](https://developer.okta.com/docs/reference/core-okta-api/#operators)**
>
> Learn how the Okta API works and learn about the compatibility rules and design principles.

---

<div class="post-metadata">

**Author:** ![figandbones](https://avatars.discourse-cdn.com/v4/letter/f/bbe5ce/32.png) [@figandbones](https://devforum.okta.com/u/figandbones)\
**Post date:** [March 22, 2024, 5:26pm UTC](https://devforum.okta.com/t/search-for-users-by-email-domain/27351/3 "2024-03-22T17:26:26Z")

</div>

Thanks Erik,

That explains the error. But I still need to find how to do the domain query.

Diana

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/oktadev/original/1X/589c4c5f80de422d01f47cee7185a7fb8227835c.png) [@system](https://devforum.okta.com/u/system)\
**Post date:** [April 21, 2024, 5:26pm UTC](https://devforum.okta.com/t/search-for-users-by-email-domain/27351/4 "2024-04-21T17:26:53Z")

</div>

Closed on April 21, 2024, 5:26pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
