# management.usersByEmail not recognized in login action

**URL:** <https://community.auth0.com/t/management-usersbyemail-not-recognized-in-login-action/121350>\
**Category:** Get Help\
**Tags:** users-by-email, management-api\
**Created:** [November 21, 2023, 4:20pm UTC](https://community.auth0.com/t/management-usersbyemail-not-recognized-in-login-action/121350 "2023-11-21T16:20:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmoreno](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/cmoreno/32/52173_2.png) [@cmoreno](https://community.auth0.com/u/cmoreno)\
**Post date:** [November 21, 2023, 4:20pm UTC](https://community.auth0.com/t/management-usersbyemail-not-recognized-in-login-action/121350/1 "2023-11-21T16:20:45Z")

</div>

Hi,

Got stuck here while migrating auth0 rule to action. Specifically with getting the users by email using the ManagementClient. Was expecting that this would work seamlessly as it did with Auth0 Rules.

```auto
const auth0 = require("auth0");

exports.onExecutePostLogin = async (event, api) => {
  const ManagementClient = auth0.ManagementClient;

  const management = new ManagementClient({
    clientId: event.secrets.AUTH0_CLIENT_ID,
    clientSecret: event.secrets.AUTH0_CLIENT_SECRET,
    domain: event.secrets.DOMAIN
  });

  management.usersByEmail(event.user.email, function (err, users) {
    cb(err, users);
  });
};

```

With the code block above, I’m getting this error:

```auto
{
  "message": "management.usersByEmail is not a function",
  "name": "TypeError",
  "stack": "TypeError: management.usersByEmail is not a function\n at auth0 (/data/io/node18-actions/f46fc91e-a5f3-4450-a202-542fd964e6c1/webtask.js:41:18)\n at /data/layers/layers-5gZU/5gZUD7V-iEoZT02eg2ioFvNp4q4jyGU1398DwYiP6sM/node_modules/async/dist/async.js:3676:28\n at replenish (/data/layers/layers-5gZU/5gZUD7V-iEoZT02eg2ioFvNp4q4jyGU1398DwYiP6sM/node_modules/async/dist/async.js:448:21)\n at /data/layers/layers-5gZU/5gZUD7V-iEoZT02eg2ioFvNp4q4jyGU1398DwYiP6sM/node_modules/async/dist/async.js:453:13\n at eachOfLimit (/data/layers/layers-5gZU/5gZUD7V-iEoZT02eg2ioFvNp4q4jyGU1398DwYiP6sM/node_modules/async/dist/async.js:479:36)\n at awaitable (/data/layers/layers-5gZU/5gZUD7V-iEoZT02eg2ioFvNp4q4jyGU1398DwYiP6sM/node_modules/async/dist/async.js:212:32)\n at eachOfGeneric (/data/layers/layers-5gZU/5gZUD7V-iEoZT02eg2ioFvNp4q4jyGU1398DwYiP6sM/node_modules/async/dist/async.js:514:16)\n at eachOf (/data/layers/layers-5gZU/5gZUD7V-iEoZT02eg2ioFvNp4q4jyGU1398DwYiP6sM/node_modules/async/dist/async.js:628:16)\n at awaitable (/data/layers/layers-5gZU/5gZUD7V-iEoZT02eg2ioFvNp4q4jyGU1398DwYiP6sM/node_modules/async/dist/async.js:212:32)\n at /data/layers/layers-5gZU/5gZUD7V-iEoZT02eg2ioFvNp4q4jyGU1398DwYiP6sM/node_modules/async/dist/async.js:3675:9"
}

```

Just for verifying that I’m using the correct function name:

```auto
usersByEmail: UsersByEmailManager {
    configuration: {
      clientId: 'cf7EiMQP9nGVE3tvuXKjfIFFi33WoniO',
      clientSecret: 'QVge4qMxzSISJASGYuUr9_bw5HCSaEBlvVinLVKBeJ3H-Vl_2PqFxJfcF9beClIV',
      domain: 'bark-sandbox.us.auth0.com',
      scope: 'read:users',
      baseUrl: 'https://bark-sandbox.us.auth0.com/api/v2',
      middleware: [Array],
      parseError: [AsyncFunction: parseError]
    },
    fetchWithTimeout: [AsyncFunction (anonymous)],
    fetch: [AsyncFunction (anonymous)],
    middleware: [[TokenProviderMiddleware], [TelemetryMiddleware] ],
    fetchApi: [AsyncFunction: fetch],
    parseError: [AsyncFunction: parseError],
    timeoutDuration: 10000
  }

```

What am I missing here?

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [November 21, 2023, 6:07pm UTC](https://community.auth0.com/t/management-usersbyemail-not-recognized-in-login-action/121350/3 "2023-11-21T18:07:47Z")

</div>

Hi @cmoreno,

Recently, there was an update to the ManagementClient API. As part of this update, some of the methods underwent name changes.

The revised call to get users by email is now `management.usersByEmail.getByEmail(requestParameters)`.

(Reference: [UsersByEmailManager | auth0](https://auth0.github.io/node-auth0/classes/management.UsersByEmailManager.html#getByEmail))

After implementing these updates in your Post Login action script, you should be able to get the user by email without any issues.

Please reach out if you encounter any difficulties.

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![cmoreno](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/cmoreno/32/52173_2.png) [@cmoreno](https://community.auth0.com/u/cmoreno)\
**Post date:** [November 22, 2023, 8:30am UTC](https://community.auth0.com/t/management-usersbyemail-not-recognized-in-login-action/121350/4 "2023-11-22T08:30:29Z")

</div>

Hi @rueben.tiow,

Thank you for the quick response and documentation reference, though I’ve tried to replace the code with it but still getting the same error:

```auto
{
  "message": "management.getByEmail is not a function",
  "name": "TypeError",
  "stack": "TypeError: management.getByEmail is not a function\n at auth0 (/data/io/node18-actions/1a95326b-d2a4-4900-88a8-6d00ef57ddea/webtask.js:42:18)\n at /data/layers/layers-6lE4/6lE4f8h7liL-nqfuQmcOgvIvjrx_nYJrhIepd4yG4SY/node_modules/async/dist/async.js:3676:28\n at replenish (/data/layers/layers-6lE4/6lE4f8h7liL-nqfuQmcOgvIvjrx_nYJrhIepd4yG4SY/node_modules/async/dist/async.js:448:21)\n at /data/layers/layers-6lE4/6lE4f8h7liL-nqfuQmcOgvIvjrx_nYJrhIepd4yG4SY/node_modules/async/dist/async.js:453:13\n at eachOfLimit (/data/layers/layers-6lE4/6lE4f8h7liL-nqfuQmcOgvIvjrx_nYJrhIepd4yG4SY/node_modules/async/dist/async.js:479:36)\n at awaitable (/data/layers/layers-6lE4/6lE4f8h7liL-nqfuQmcOgvIvjrx_nYJrhIepd4yG4SY/node_modules/async/dist/async.js:212:32)\n at eachOfGeneric (/data/layers/layers-6lE4/6lE4f8h7liL-nqfuQmcOgvIvjrx_nYJrhIepd4yG4SY/node_modules/async/dist/async.js:514:16)\n at eachOf (/data/layers/layers-6lE4/6lE4f8h7liL-nqfuQmcOgvIvjrx_nYJrhIepd4yG4SY/node_modules/async/dist/async.js:628:16)\n at awaitable (/data/layers/layers-6lE4/6lE4f8h7liL-nqfuQmcOgvIvjrx_nYJrhIepd4yG4SY/node_modules/async/dist/async.js:212:32)\n at /data/layers/layers-6lE4/6lE4f8h7liL-nqfuQmcOgvIvjrx_nYJrhIepd4yG4SY/node_modules/async/dist/async.js:3675:9"
}

```

I’ve attached the dependencies of my action. So for the auth0, I’m using the latest one.

 ![dependencies](https://global.discourse-cdn.com/auth0/original/3X/d/3/d3d0aa6cb74014f0e186bfa12b9071ca56725fdb.png)

---

<div class="post-metadata">

**Author:** ![cmoreno](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/cmoreno/32/52173_2.png) [@cmoreno](https://community.auth0.com/u/cmoreno)\
**Post date:** [November 23, 2023, 10:43am UTC](https://community.auth0.com/t/management-usersbyemail-not-recognized-in-login-action/121350/5 "2023-11-23T10:43:29Z")

</div>

This solved the issue for me:

```auto
management.usersByEmail.getByEmail({ email: event.user.email }
).then(response => {
    console.log(response.data);
}).catch(err => {
    console.log(err);
});

```

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [November 28, 2023, 5:52pm UTC](https://community.auth0.com/t/management-usersbyemail-not-recognized-in-login-action/121350/6 "2023-11-28T17:52:52Z")

</div>

Hi @cmoreno,

I’m glad you were able to solve the issue and thank you for sharing the solution with the rest of the Community!

Please reach out again if you have any further questions.

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [December 12, 2023, 5:53pm UTC](https://community.auth0.com/t/management-usersbyemail-not-recognized-in-login-action/121350/7 "2023-12-12T17:53:07Z")

</div>

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