# Auth0 4.10.0, NodeJS, and the impossible ManagementClient

**URL:** <https://community.auth0.com/t/auth0-4-10-0-nodejs-and-the-impossible-managementclient/150001>\
**Category:** Get Help\
**Tags:** management-api, roles\
**Created:** [October 16, 2024, 7:25pm UTC](https://community.auth0.com/t/auth0-4-10-0-nodejs-and-the-impossible-managementclient/150001 "2024-10-16T19:25:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cubap](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/cubap/32/3938_2.png) [@cubap](https://community.auth0.com/u/cubap)\
**Post date:** [October 16, 2024, 7:25pm UTC](https://community.auth0.com/t/auth0-4-10-0-nodejs-and-the-impossible-managementclient/150001/1 "2024-10-16T19:25:45Z")

</div>

I’ve been in a battle with on-site AI, who keeps giving me broken code. I am frustrated by the changes to the ManagementClient for NodeJS which seems to have removed a lot of functionality or forced it into direct API calls.

In short, I have a web interface where “admin” users are changing the roles on other users. The backend uses the ManagementClient to update the users. I found work arounds for all the functionality until I get to the last step where I want to replace role “A” with role “B”. I can assign Roles, but not delete them.

Here’s the old code that worked (abridged):

```auto
const ROLES = [
  process.env.ROLE_ADMIN_ID,
  process.env.ROLE_INACTIVE_ID,
  process.env.ROLE_PUBLIC_ID
]

let manager = new ManagementClient({
  domain: process.env.DOMAIN,
  clientId: process.env.CLIENTID,
  clientSecret: process.env.CLIENT_SECRET,
  scope:
    "create:users read:users read:user_idp_tokens update:users delete:users read:roles create:roles update:roles delete:roles"
})

router.get("/getAllUsers", async function (req, res, next) {
// ...
const fetchUsersInRoles = ROLES.map((id) =>
          manager.getUsersInRole({id}))
// ...

router.post("/assignRole", async function (req, res, next) {
// ...
         manager.assignRolestoUser({id: userid}, {roles: [roleID]})
        .then((result) => {
          const dataObj = {
            roles: ROLES.filter(
              (justAdded) => justAdded !== roleID)
          }

          manager.removeRolesFromUser({id: userid}, dataObj)
            .then((resp2) => {
              res.status(200)
                .send(`role was successfully assigned to the user`))
            })

```

This looks mostly like what the AI keeps recommending. By investigating the classes in the Auth0 code, I discovered a few workarounds…

` manager.getUsersInRole` became `manager.roles.getUsers`  
`manager.assignRolestoUser` became `manager.users.assignRoles`

but `manager.users.removeRoles` does not exist! The AI finally said I could use `manager.resourceServers.delete({ id: `users/${userid}/roles`, data }) but when I added the `delete:resource\_servers` scope to my ManagementClient, I still got the 401 error saying that I didn’t.

I’m so frustrated. I’ve lost two days and now I’ve got lots of users with conflicting roles that I can’t fix unless I manually make the changes. What am I missing? Something obvious must be here. Is there a `unassignRoles` or `nukeRoles` that I am not seeing?

---

<div class="post-metadata">

**Author:** ![dawid.matuszczyk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dawid.matuszczyk/32/74550_2.png) [@dawid.matuszczyk](https://community.auth0.com/u/dawid.matuszczyk)\
**Post date:** [October 17, 2024, 10:45am UTC](https://community.auth0.com/t/auth0-4-10-0-nodejs-and-the-impossible-managementclient/150001/2 "2024-10-17T10:45:26Z")

</div>

Hi @cubap

Welcome to the Auth0 Community!

Thank you for posting your question, in terms of removing roles from the user you should be able to use [deleteRoles](https://auth0.github.io/node-auth0/classes/management.UsersManager.html#deleteRoles).

> **[UsersManager | auth0](https://auth0.github.io/node-auth0/classes/management.UsersManager.html#deleteRoles)**
>
> Documentation for auth0

Thanks  
Dawid

---

<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:** [October 31, 2024, 10:45am UTC](https://community.auth0.com/t/auth0-4-10-0-nodejs-and-the-impossible-managementclient/150001/3 "2024-10-31T10:45:57Z")

</div>

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