Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Users in specified role(s) #300

Closed
chrisbonilla95 opened this issue Aug 23, 2017 · 3 comments
Closed

Get Users in specified role(s) #300

chrisbonilla95 opened this issue Aug 23, 2017 · 3 comments
Assignees
Milestone

Comments

@chrisbonilla95
Copy link
Contributor

Is there a way to get all the users in a certain role? Can't seem to find it and pulling all users and then filtering is quite inefficient when you have a lot of end-users. I for example just want to currently pull agents and admins

I found this on zendesk https://developer.zendesk.com/rest_api/docs/core/users#filters

@chrisbonilla95
Copy link
Contributor Author

chrisbonilla95 commented Aug 23, 2017

Don't know if this is the cleanest way to do it, but could you not just add a parameter to GetAllUsers that takes a list of roles (ex. List roles = null) and then modify the method as follows:

public GroupUserResponse GetAllUsers(int? perPage = null, int? page = null, UserSideLoadOptions sideLoadOptions = UserSideLoadOptions.None, List<string> roles = null)
        {
            string resourceString = "users.json";

            if (roles != null && roles.Count > 0)
            {
                resourceString += "?";

                foreach (var role in roles)
                {
                    resourceString += "role[]=" + role + "&";
                }

                resourceString = resourceString.TrimEnd('&');
            }
            
            string resource = GetResourceStringWithSideLoadOptionsParam(resourceString, sideLoadOptions);

            return GenericPagedGet<GroupUserResponse>(resource, perPage, page);
        }

I tried building to test, but I keep getting errors about versions strings and metadata.

@chrisbonilla95
Copy link
Contributor Author

chrisbonilla95 commented Aug 23, 2017

So I figured out building it and added the dll to my project to test and can confirm that it works.
I also tried sending just 1 role since it says to use role[]= for more than 1 and role= for just 1 and role[] works just fine for just 1 role sent as well, so that should probably be used since it'll work for either scenario.

I just added to that method because it was easy/quick, but perhaps it makes sense to create separate methods, like GetAllAgents, GetAllEndUsers, GetAllAdmins and GetAllUsersInRoles.

Also, there's enterprise roles that use different query string (permission_set={role_id}) and that can only be called 1 at a time, so might want another method for that too.

Just my 2 cents, thanks for all you're hard work, makes my life much easier!

@mozts2005 mozts2005 self-assigned this Aug 23, 2017
@mozts2005 mozts2005 added this to the 3.7.1 milestone Aug 23, 2017
@mozts2005 mozts2005 mentioned this issue Aug 24, 2017
@mozts2005
Copy link
Member

All looks good to me Please test the myget build https://www.myget.org/feed/zendeskapi_v2_prerelease/package/nuget/ZendeskApi_v2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants