Zendesk - How to get users based on roles?

423 views Asked by At

I am using Elizabeth's wrapper from https://github.com/mozts2005/ZendeskApi_v2

I want to pull a list of agents. I don't see any built in Function that will allow that.

I have tried using the endpoint of /api/v2/users.json?role=agent with the GetAllUsers() function but it still returns all of them.

Right now, I am going to add a custom field to be able to search for them, but that should not be the case, especially since Zendesk's API does have an option for returning users based on their role: /api/v2/users.json?role[]=admin&role[]=end-user

Can anyone help me out?

1

There are 1 answers

0
mabe02 On

You can give a try to the Zendesk Search API:

from urllib.parse import urlencode
import requests

results = [] # Empty list to collect pagination results

credentials = 'your_zendesk_email', 'your_zendesk_password'
session = requests.Session()
session.auth = credentials

params = {
    'query': 'type:user role:agent'
}

url = 'https://your_subdomain.zendesk.com/api/v2/search.json?' + urlencode(params)

while url:
    response = session.get(url)
    data = response.json()
    results += data['results']
    url = data['next_page'] # should return false according to the doc when the last page is reached

Useful resources:

Search endpoint seems to be supported also in the c# library you are using.