lanej / zendesk2

Zendesk API V2 client using Cistern
http://lanej.io/zendesk2/
MIT License
25 stars 28 forks source link

How to specify role when getting all users? #65

Closed dbuskariol closed 5 years ago

dbuskariol commented 6 years ago

So based off the Zendesks API docs, I should be able to pass in role key with value of agent, admin or end_user. I am trying the following:

client.users.all("role" => "agent", "page" => 1, "per_page" => 1)

But it's still only giving me all users. I can tell this as the next_page url is the standard https://{subdomain}.zendesk.com/api/v2/users.json?page=2 with way too high of a count, instead of the expected https://{subdomain}.zendesk.com/api/v2/users.json?page=2&role=agent&per_page=1.

Am I missing something here?

dbuskariol commented 6 years ago

It looks like the gem is not actually passing the role through to the API

GET /api/v2/users.json?page=1&per_page=1 HTTP/1.1
User-Agent: Ruby/2.4.1 (x86_64-linux; ruby) Zendesk2/1.12.0 Faraday/0.15.2
Authorization: Basic <snip>
Accept-Encoding: gzip, deflate
Accept: */*
Connection: close
Host: github.zendesk.com
lanej commented 6 years ago

@dbuskariol

You need to use the search collection method to obtain filtered results.

z.users.search('role' => 'foo')
I, [2018-07-10T09:00:20.030336 #99393]  INFO -- : get => https://x.zendesk.com/api/v2/search.json
D, [2018-07-10T09:00:20.030403 #99393] DEBUG -- request: User-Agent: "  Ruby/2.5.1 (x86_64-darwin17; ruby) Zendesk2/1.12.0 Faraday/0.13.1\n"
Authorization: "Basic XYZ"
Content-Type: "application/json"
D, [2018-07-10T09:00:20.030429 #99393] DEBUG -- request.body: {"query":"role:foo type:user"}
I, [2018-07-10T09:00:20.511346 #99393]  INFO -- : 200 <= https://x.zendesk.com/api/v2/search.json
D, [2018-07-10T09:00:20.511462 #99393] DEBUG -- response: server: "nginx"
date: "Tue, 10 Jul 2018 16:00:20 GMT"
content-type: "application/json; charset=UTF-8"
transfer-encoding: "chunked"
connection: "close"
x-frame-options: "SAMEORIGIN"
cache-control: "max-age=10, private"
x-rate-limit: "700"
x-rate-limit-remaining: "697"
strict-transport-security: "max-age=31536000;"
x-content-type-options: "nosniff"
D, [2018-07-10T09:00:20.511501 #99393] DEBUG -- response.body: {"results":[],"facets":null,"next_page":null,"previous_page":null,"count":0}

see:

https://github.com/lanej/zendesk2/blob/1da4fa9234e8f7e48dd784789557df16c47d845c/spec/users_spec.rb#L47-L80