Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Is search supported? #54

Closed
pehrlich opened this Issue · 9 comments

4 participants

@pehrlich

From what I can figure out, it looks like methods correspond to URLs, with some intelligence/guessing:

# the query option is silently dropped
# https://github.com/zendesk/zendesk_api_client_rb/issues/47 maybe?
> $zendesk.ticket(query: 'moon').first
get https://juniper.zendesk.com/api/v2/tickets

# typos are passed to ZenDesk API
> $zendesk.tickts(query: 'moon').first
get https://juniper.zendesk.com/api/v2/tickts?query=moon
the server responded with status 404
{"error"=>"InvalidEndpoint", "description"=>"Not found"}

# notice that user becomes users:
 > $zendesk.user(query: 'moon').count
get https://juniper.zendesk.com/api/v2/users?query=moon

$zendesk.search(query: 'moon').first
NoMethodError: undefined method `superclass' for ZendeskAPI::Search:Module

How would I run a search, such as the following (which is a valid call)?

# simple
curl "https://juniper.zendesk.com/api/v2/search.json?query=type:moon" -v -u email:pasword
# typed:
 curl "https://juniper.zendesk.com/api/v2/search.json?query=type:ticket%20moon" -v -u email:pasword

Edit: #29 suggests client.users.search(:query => email). How would I find this user's tickets?

Thanks!

@steved
Owner

Your last call is correct, though there was a bug in the client and it should be fixed in master. There should be a new release within a couple days. Doing $zendesk.search(query: 'type:moon').first will then work.

You may also search tickets by requester, assignee, etc. See https://support.zendesk.com/entries/20239737-zendesk-search-reference. However, if you already have a user instance, you can just call User#tickets.

@steved
Owner

Just released a new version, 0.1.7 that should fix your problem. Thanks!

@steved steved closed this
@steved steved reopened this
@pehrlich

Yay, it works!

But if I change the parameters, the query doesn't get run again. I think this is a known issue?

Is there a workaround to clear the cache?

@steved
Owner

Cool.

To clear the cache, use the :reload option

client.search(:query => 'new query', :reload => true)

I'll add in an option to do something like, if it's preferable:

search = client.search(:query => 'query')
search.fetch # => returns results for /api/v2/search?query=query
search.options[:query] = 'new_query'
search.fetch(true) # => returns results for /api/v2/search?query=new_query
@steved
Owner

Thinking about it, a the client cache should probably be based on the parameters passed in as well.

@steved
Owner

Added to the master (240f3aa)

@steved steved closed this
@benilovj

Is this the only place that search is documented? I could not find any mention of it in the README or in the rdoc.

@steved
Owner

I guess, unfortunately, it is. I'll add it the README and look into expanding the ZendeskAPI::Client rdoc.

@jaykilleen

Man I am struggling with the Zendesk API search feature. I don't mind the Zendesk documentation API on the website but it is all curl based and I'd like it to be ruby. I'll raise a seperate issue for the particular searches I am trying to do, just simple things like user.tickets. I guess just trying to reiterate benilovj's point from two years ago that it would be nice to expand the rdoc... :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.