How to search using API client? #10

brainlid opened this Issue May 21, 2012 · 4 comments


None yet
2 participants

How do I search using the API client? The documentation shows the API supports it using a "search" action on a user (for instance). -

Specifically, I'm trying to search for a user by email.

All the following attempts return the full list of users paged in 100's.

zendesk_user = Zendesk::User.find(client, {:email => ''})
zendesk_user = Zendesk::User.find(client, :params => {:search => ''})
zendesk_user = Zendesk::User.find(client, :search => {:email => ''})

How do I use the API client to search for Users, Organizations, etc? I looked in the gem but didn't see any code or tests for this feature.


steved commented May 22, 2012

User searching is available through => "")

Generic searching is available through => "")

The latter doesn't currently doesn't auto-detect the class of the result (just dumping them in a generic Search object), but that will hopefully come soon.
Both return collections.

Thanks for pointing me in the right direction. I had to look into the Zendesk::Collection class to figure out what to do with the created search query collection. I suggest documenting how search works on the Readme.

Here's how I understand it to work.

Create a query definition

query = => "")

Execute the query and fetch the results

users = query.fetch
# => 1
# => ""

steved commented May 22, 2012

The query is executed on demand. So something like

query = => "")

Will execute the query and return the first user. Though calling #count currently doesn't execute the query first. That is a bug, and will be fixed.

Thanks for the answer. This resolved my issue. And yes, my initial problem was I used "count" to try and figure out if data was being returned.

brainlid closed this May 23, 2012

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