# Auth0 ManagementClient not working from Post User Registration action

**URL:** <https://community.auth0.com/t/auth0-managementclient-not-working-from-post-user-registration-action/93760>\
**Category:** Get Help\
**Tags:** extensibility, actions-extensibility\
**Created:** [November 4, 2022, 9:12pm UTC](https://community.auth0.com/t/auth0-managementclient-not-working-from-post-user-registration-action/93760 "2022-11-04T21:12:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anders.rawlins](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/anders.rawlins/32/33385_2.png) [@anders.rawlins](https://community.auth0.com/u/anders.rawlins)\
**Post date:** [November 4, 2022, 9:12pm UTC](https://community.auth0.com/t/auth0-managementclient-not-working-from-post-user-registration-action/93760/1 "2022-11-04T21:12:43Z")

</div>

I am trying to programmatically assign a role to a user after they’ve registered using a “Post User Registration” action and the auth0 npm module. However I’m getting the following error when running the action in Test: “APIError: getaddrinfo ENOTFOUND https”

Here is the code:

```auto
exports.onExecutePostUserRegistration = async (event) => {
  const user = event.user;
  const ManagementClient = require("auth0").ManagementClient;
  const auth0 = new ManagementClient({
    domain: event.secrets.DOMAIN,
    clientId: event.secrets.CLIENT_ID,
    clientSecret: event.secrets.CLIENT_SECRET,
    scope: 'read:roles update:users create:role_members',
  });
  const params = { id: user.user_id };
  const data = { roles: [event.secrets.ROLE_ID] };
  
  await auth0.users.assignRoles(params, data);  
}

```

And here is the full stack trace

```auto
APIError: getaddrinfo ENOTFOUND https
    at /data/layers/layers-tdaR/tdaR0pdb0MnYXTf0YLgjesmRJnnEWEwwoVWzGvGbizg/node_modules/rest-facade/src/Client.js:402:25
    at Request.callback (/data/layers/layers-tdaR/tdaR0pdb0MnYXTf0YLgjesmRJnnEWEwwoVWzGvGbizg/node_modules/superagent/lib/node/index.js:905:3)
    at ClientRequest.<anonymous> (/data/layers/layers-tdaR/tdaR0pdb0MnYXTf0YLgjesmRJnnEWEwwoVWzGvGbizg/node_modules/superagent/lib/node/index.js:822:12)
    at ClientRequest.emit (node:events:527:28)
    at ClientRequest.emit (node:domain:475:12)
    at TLSSocket.socketErrorListener (node:_http_client:454:9)
    at TLSSocket.emit (node:events:527:28)
    at TLSSocket.emit (node:domain:475:12)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)

```

Is there another way I should be doing this?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [November 8, 2022, 4:23pm UTC](https://community.auth0.com/t/auth0-managementclient-not-working-from-post-user-registration-action/93760/3 "2022-11-08T16:23:51Z")

</div>

Hi @anders.rawlins,

Welcome to the Auth0 Community!

Can you try removing the **https://** from your `event.secrets.domain`?

IIRC, _domain_ is expecting something like `mycompany.auth0.com`.

---

<div class="post-metadata">

**Author:** ![anders.rawlins](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/anders.rawlins/32/33385_2.png) [@anders.rawlins](https://community.auth0.com/u/anders.rawlins)\
**Post date:** [November 9, 2022, 4:44pm UTC](https://community.auth0.com/t/auth0-managementclient-not-working-from-post-user-registration-action/93760/4 "2022-11-09T16:44:21Z")

</div>

That worked @dan.woda , thank you!

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [November 9, 2022, 4:44pm UTC](https://community.auth0.com/t/auth0-managementclient-not-working-from-post-user-registration-action/93760/5 "2022-11-09T16:44:51Z")

</div>

Perfect, let us know if you run into anything else. Thanks!

---

<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:** [November 23, 2022, 4:45pm UTC](https://community.auth0.com/t/auth0-managementclient-not-working-from-post-user-registration-action/93760/6 "2022-11-23T16:45:24Z")

</div>

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