Searching with the Zendesk API

Have more questions? Submit a request

32 Comments

  • Jehan
    Comment actions Permalink

    Hi,


    I am having problem sorting the search result for Article. Sort_by and order_by are not working for help center search api. Here is the api request url.


    /api/v2/help_center/articles/search.json?section=115000143525,203213189&sort_by=created_at&sort_order=desc&include=sections&per_page=4


    I don't know how the results returned through search api are sorted. I want the latest articles to come first and then so on.


    Thanks,


    Jehan

    0
  • Pankaj Moholkar
    Comment actions Permalink

    Is there a way to post search string to ZenDesk search page from external application, so that we can display results on https://subdomain.zendesk.com/agent/search page?

    0
  • Rebecca
    Comment actions Permalink

    Hi Pankaj- 

    The url for in-product Support search is not modified to include the search parameters when a search occurs so it would not be possible to implement this type of behavior from an external tool. Our Search API would offer this functionality programmatically .../api/v2/search.json?query={search_string}. However, I am not sure I fully understand your use case so feel free to elaborate and I'd be happy to see what we can offer!

    0
  • Pankaj Moholkar
    Comment actions Permalink

    Hi Rebecca,


    If not url parameter, can I POST the search-text in JSON package (or something like that) to some URL, so that it opens ZenDesk search page with results?


    Basically, I want to execute the same action as the searchbox in ZenDesk UI and display results on the search page. But I want to be able to do it from my application. i.e. If I click on a link, it should redirect to ZenDesk search page with the link text and fetch results for that text. Can I use some json/action/page to POST the serach-text to the search page?


    Yes, I can fetch results using search APIs and display it on my own UI but that will be probably the last option.


    Thanks for your help.

    0
  • Rebecca
    Comment actions Permalink

    Thank you for the additonal context, Pankaj!


    After reading over what you're hoping to do, unfortunately I am not aware of any method to accomplish this workflow using an Zendesk App or an external application. The Search API is likely the best option we offer at this time. 

    0
  • UserAdmin #55555
    Comment actions Permalink

    Is there a way I can query for the json result of all my custom ticket field entries for "Custom field ID 2967xx97"?

     

    0
  • Bryan Flynn
    Comment actions Permalink

    No, not right now at least (Aug 2018). You can do a search against custom fields using the "fieldvalue" keyword but it searches across all custom fields. This is a known limitation that our team is looking into but no ETA on when field specific searches might become available.

    0
  • Mike C
    Comment actions Permalink

    I'm getting inconsistent results from the search API.   Tickets in our system have several custom files.  One of them is a group ID.  There is only one ticket with status < closed with a given group ID.  At one point in our workflow, an agent will set the ticket to the Solved status.  I have an app that finds the ticket in the Solved status and sets the status to Open using the Core API.  If I immediately search for that ticket in the search API only on the group ID, I find it with the Open status.  If I search for that ticket with the Group ID and  with "status<pending", nothing is returned.  After some period of time, this query will return ticket.  But if I query immediately after the update, nothing is found.  Is this expected behavior?  

    0
  • Joseph May
    Comment actions Permalink

    Hi Mike-

    Yes this is expected. As documented under our Core API:

    Note: It can take up to a few minutes for new tickets, users, and other resources to be indexed for search. If new resources don't appear in your search results, wait a few minutes and try again.

    0
  • Mike C
    Comment actions Permalink

    Thanks Joseph-

    Just to clarify, does this apply to updates as well as new tickets?

    0
  • Joseph May
    Comment actions Permalink

    Sure Mike, and yes, it does - though I can see why you would need to ask this, as we specify only 'new'. We document it elsewhere, as new or modified. This has also been my experience.

    0
  • Francisco Oirdobro
    Comment actions Permalink

    Hi,

    is there a way to search with the API using AJAX?

    Thanks

    0
  • Bryan Flynn
    Comment actions Permalink

    Hi Francisco. Yes, Zendesk APIs can be called via AJAX. I'd check out the API Getting Started section of the docs and start with an overview. If you have follow-up questions, you can post to the online REST APIs community topic or reach us at support@zendesk.com.

    I just found this article, too, that gives an AJAX example: Adding KB search to your website with AJAX

    0
  • Igor Rocha
    Comment actions Permalink

    Hi Charles,

    one of the resources you mentioned in your post,

    is no longer available online. There's a different mirror for it, though, available here.

    Another alternative for learning Python are online courses, most of which can be found here.

    0
  • Charles Nadeau
    Comment actions Permalink

    Thanks, Igor! I replaced the link with a link to the learning resources listed on the python.org wiki.

    1
  • Kevin J. Hogan
    Comment actions Permalink

    I am new to Zendesk and have been tasked with extracting tickets.  I have tried both methods via curl and each time have received the message {"error":"Couldn't authenticate you"}* Connection #0 to host {mysubdomain}.zendesk.com left intact.

    here are the 2 curl commands i tried:

    curl "https://{mysubdomain}.zendesk.com/api/v2/search.json?query=type%3Aticket+status%3Aopen" -v -u email@address.com:mypassword
    curl "https://{mysubdomain}.zendesk.com/api/v2/search.json" -G --data-urlencode "query=type:ticket status:open" -v -u email@address.com:mypassword

    Any help would be appreciated.

     

     

    0
  • Joseph May
    Comment actions Permalink

    Hi Kevin-

    To begin, have you checked to make sure both password and token access are enabled at https://{subdomain}.zendesk.com/agent/admin/api/settings? That is a likely culprit.
    Also, I might recommend considering an endpoint other than Search to accomplish this, as we are making some changes. Depending on the data you are required to extract would determine which endpoint(s) might suit you best, whether that be Tickets or Incremental Exports.

    0
  • Anurag Toshniwal
    Comment actions Permalink

    Hi Zendesk Team,

    I've been trying to leverage the Search API with Python to fetch all "Incident" type tickets for a given date but I keep getting partial result - the endpoint returns all incident type tickets but does not honor the date parameter; I'm getting incident type tickets created on other dates as well. 

    Below is the endpoint that I'm using. Can someone please provide some insights? Thanks!

    <sub-domain>/api/v2/search.json?query=created:2019-09-06&ticket_type:incident
    0
  • Jonathan March
    Comment actions Permalink

    @Anurag, does it help if you "quote" your date?

    0
  • Anurag Toshniwal
    Comment actions Permalink

    Hi @Jonathan,

    I put the date in "quotes" but I'm still getting a few tickets that were created on 2019-09-07

     

    0
  • Jonathan March
    Comment actions Permalink

    That sounds like a time zone issue.

    0
  • Anurag Toshniwal
    Comment actions Permalink

    Hmm, can you direct me to some documentation that can show me how to deal with this issue?

    0
  • Bryan Flynn
    Comment actions Permalink

    Hi Anurag.

    While not that obvious, the "query" parameter is the only HTTP request parameter being sent here. Putting an ampersand/& character essentially creates a new parameter that's not recognized (and thus ignored).

    If running from your browser, try:

    <sub-domain>/api/v2/search.json?query=created:2019-09-06 ticket_type:incident

    If running from, say, the command line using cURL, try:

    curl -v -u username@example.com:password https://your_subdomain.zendesk.com/api/v2/search -G --data-urlencode "query=created:2019-09-06 ticket_type:incident"

    Here's some references that maybe you've already checked out, but I'll list them anyway. They each add to the overall "Search" picture...

    Searching Tickets:

    https://support.zendesk.com/hc/en-us/articles/203663206-Searching-tickets

    Zendesk Support search reference:

    https://support.zendesk.com/hc/en-us/articles/203663226-Zendesk-Support-search-reference

    Zendesk Support advanced search:

    https://support.zendesk.com/hc/en-us/articles/217385687-Zendesk-Support-advanced-search

    Search API reference:

    https://developer.zendesk.com/rest_api/docs/support/search

    In this last reference link, you can see that there are three HTTP parameters that can be passed -- "query", "sort_by", and "sort_order". Like I said, it's not that obvious. When you add possible encoding that might be needed along with a HTTP query parameter called "query", things can get a bit confusing.

    0
  • Sam
    Comment actions Permalink

    Regarding the Python example, it's not necessary to encode the passed parameters. The magical Requests library does all URL encoding for the user as long as the params are passed correctly. This should be done as follows:

    url = 'https://your_subdomain.zendesk.com/api/v2/search.json'

    params = {
        'query': 'type:ticket status:open',
        'sort_by': 'created_at',
        'sort_order': 'asc',
    }

    response = session.get(url, params=params)
    0
  • Adnan
    Comment actions Permalink

    I'm trying to use API token to do get request but seems not to be working, can someone help how to do this in python?

    credentials = 'myemail/token:6h2gouafy69ubSTklEJlHXnj1Cxxxxx'
    session = requests.Session()
    session.auth = credentials

    params = {

        'query': 'type:ticket tags:"send_whatsapp" status<closed',

    }

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

    response = session.get(url,headers={'Authorization': credentials}

    )

    if response.status_code != 200:

        print('Status:', response.status_code,

              'Problem with the request. Exiting.')

        exit()
    0
  • Sam
    Comment actions Permalink

    @adnan You're doing a few things wrong here. First, credentials are incorrectly passed. Second, parameters should be passed using requests built-in kwarg. Try this:

    import requests

    credentials = ("username@domain/token", "6h2gouafy69ubSTklEJlHXnj1Cxxxxx")
    session = requests.Session()
    session.auth = credentials

    url = 'https://propertypro.zendesk.com/api/v2/search.json'
    params = {'query': 'type:ticket tags:"send_whatsapp" status<closed'}

    try:
    response = session.get(url, params=params)
    response.raise_for_status()

    except requests.exceptions.HTTPError as e:
    code = e.response.status_code
    print(f'Status {code}: {e}. Problem with the request. Exiting.')
    exit()

    I highly suggest reading the requests docs thoroughly, and the Zendesk introductions and examples. Even better, use a Python Zendesk wrapper lib.

     

    EDIT: Forgot indents in code block

    1
  • Adnan
    Comment actions Permalink

    thank you for the swift reply Sam!!

    0
  • Nicole - Community Manager
    Comment actions Permalink

    Hey Sam - thanks for sharing that answer, and welcome to the Zendesk Community!

    0
  • Liqiong Bu
    Comment actions Permalink

    Hi Sam,

    I am facing a issue on searching api, I used search.json to /v2/search.json?query=type:ticket status:solved has_attachment:true -tag:has_attachment&sort_by=created_at&sort_order=asc

     

    to search for the tickets but the result returns the ticket that has the tag

    Did i do anything wrong on the query?

     

    Thanks

    0
  • Sam
    Comment actions Permalink

    Hi Liqiong Bu, Can you share the code you used to generate this request?

    0

Please sign in to leave a comment.

Powered by Zendesk