How to find if Logged In User is a Freshdesk Admin

Hi,
How can I find in my app if the logged In user is a Freshdesk admin ? I am using the below method to get the details of the loggedInUser.
client.data.get(‘loggedInUser’).then(function(data) {
console.log("loggedInUser data in ticketBackground.js is : ",data);
});
Which of these response parameters can help me determine if the user is admin -

Thanks in Advance !

hey @Himanshu_Sehgal

Each user role has a unique ID, from the loggedin user object you can see it has a role_ids array, if the ID of the Admin role is present in the array, then the user is an admin.

To check the role_Id of any role,

  1. Go to https://portal.freshdesk.com/a/admin/roles
  2. Click on the role that you want to find the ID for
  3. You can find the Id of the role from the page URL (if the url for a role is https://portal.freshdesk.com/a/admin/roles/48000159746/edit, then the role ID is 48000159746

Hope this helps!

Stay Safe :slight_smile:

3 Likes

Hi,
So I think I’ll have to fetch roles using the /api/v2/roles api(using admin access token taken during app installation) and then find the administrator role id’s from that response(the non editable default roles) and then compare those role ids to each element of the loggedInUser’s role id array. If a match is found then that loggedInUser is an Admin. Does it sound right or is there any other way as well ? the response of /api/v2/roles is like below -

1 Like

@Himanshu_Sehgal

That is one way to do it, but if the role changes then you have to make the changes in the code and republish the app.

so instead you can try to add the role as an Iparam, so the admin can choose to give the ID manually for the role that has to be checked, this way the if there is a change in the role it’s just configuration rather than a code change.

1 Like