Is there any way to assign roles to the user by role name instead of actual role id?

I want to assign roles to the user by role name instead of actual role id.

By sending the request POST request to api like

{
roles: [“ROLE_NAME1”, “ROLE_NAME2”]
}

Hi @saurya.dacharya,

Welcome to the Auth0 Community!

Unfortunately, this is not possible, and you must use the Role ID to make the request.

You could, however, mimic this behavior by abstracting the Role IDs as constants and calling them. For example:

const adminRole = 'ROLE_ID';
const userRole = 'ROLE_ID';
var data = { roles:[adminRole, userRole] };

Doing so should provide more natural language in the code when assigning Roles to Users.

Please let me know if there’s anything else I can do to help.

Thank you.

Thank you. This post is super helpful as I was struggling to figure out why my action failed to update the user’s role. The API docs fails to mention the correlation between role name and role id.

Using role ID makes user admin code non-portable. We have a separate dev and prod tenant, and have to adjust role IDs accordingly.

1 Like