How do I search for a role by name using the Node Management Client?

I am using Postman to call the management API and I can search for a role via name like…

https://.../api/v2/roles?name_filter=User%20Admin

But When I try to do something similar in the Management API Client…

getRoleByName(name){
    return new Promise((res, rej)=>{
      this.managementClient.getRoles({
        name
      }, async (err, roles)=>{
        if (err) rej(err);
        else {
          res(roles);
        }
      })
    })
  }

I get all of the roles back instead of the singular role I would expect. I have confirmed that name is not undefined.

I can of course just get all roles and filter or use a node http request but I would like to use the client if I can.

How can I use the Node Management API Client to get a role by name.

Hi @jgleason,

Thanks for reaching out to the Auth0 Community!

I understand that you would like to know how to search for a role by name using the Management Client.

After reviewing your code and the Management Client’s getRoles documentation, it appears that the request needs the name_filter to be specified in the request.

For example:

var name = 'testRole'
var params = {
  name_filter: name
};

management.getRoles(params, function (err, roles) {
  console.log(roles.length);
});

I hope this helps!

Please let me know if you have any additional questions, I’d be happy to help.

Thanks,
Rueben

1 Like

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