13 Comments

  • Lloyd
    Comment actions Permalink

    Hello, is there a way to pretty print the results? after our shortcuts are retrieved in the Command Prompt I have to manually format the data
    OS - Windows 7 64bit
    Terminal - "Console2"

    0
  • Charles Nadeau
    Comment actions Permalink

    @Lloyd, a Google search returns a number of solutions. The simplest in terms of setup is using the "JSON Formatter" extension in Chrome. You can get it from https://chrome.google.com/webstore/detail/json-formatter/bcjindcccaagfpapjjmafapmmgkkhgoa?hl=en. After installing it, in Chrome select Windows > Extensions, and select the "Allow access to file URLs" option for the JSON Formatter extension. This enables pretty-printing local files.

    Paste your JSON results from the console to a text file and save it with a .json extension. Then open the file in Chrome (File > Open File).

    0
  • Charles Nadeau
    Comment actions Permalink

    Troubleshooting checklist for Windows users:

    •  Confirm the crt file is a plain text file and contains the certificates. You should be able to open it in a text editor and view the certificates (the dense blocks of characters).
    • Try placing the crt file in another folder scanned by curl.exe. According to the curl docs at https://curl.haxx.se/docs/sslcerts.html, curl will look for the crt file in the following folders in order:
      • application's directory
      • current working directory
      • Windows System directory (e.g. C:\windows\system32)
      • Windows Directory (e.g. C:\windows)
      • all directories along %PATH%

    You also have the option of running cURL in an insecure mode with the -k (or –insecure) option.

    0
  • Moshe
    Comment actions Permalink

    Charles,

    First thanks so much about this article, not too many companies go out of their way to explain in such detail a 3rd party application. It's one of the reason I pushed my company to switch to Zendesk.

    To add to your comment about certificates I had similar issue, I was able to make handshake but kept getting error about the certificate.

    With the help of IT I figured out that the issue is with our web filtering software.

    Web filtering software acts like a middle man between the client and the server pinging request. In other words you are not taking directly to website, each back and forth request gets first read by the filter and then re-delivered to client/server.

    To use an industry term, having a "man in the middle" is a security risk, and most websites who use https won't allow it. (like Banks etc)

    We allowed Zendesk so traffic to  Zendesk server bypasses the filter. and it fixed the problem. 

    Thanks,

    Moshe

    0
  • Michael Fitzsimmons
    Comment actions Permalink

    One issue I has was then when I renamed cacert.pem file to curl-ca-bundle.crt it kept the .pem file extension, so it was called curl-ca-bundle.crt.pem

    Removing the .pem extension so that its .crt resolved my issue with certificates. 

    0
  • Justin
    Comment actions Permalink

    How can I add a user segment via API? Would I paste code such as the below in Terminal on my mac?

     

    curl https://{subdomain}.zendesk.com/api/v2/help_center/user_segments/{id}.json \
      -d '{ \
        "user_segment": { \
          "name": "VIP agents", \
          "user_type": "staff", \
          "group_ids": [12, ...], \
          "organization_ids": [42, ...], \
          "tags": ["vip"] \
        } \
      }' \
      -v -u {email_address}:{password} -X PUT -H "Content-Type: application/json"
    

     

    0
  • Joey
    Comment actions Permalink

    Hey Justin-

    That code would be an update to an existing segment (see the -PUT). To create a segment you would want to use this example of a POST. I would recommend using cURL for testing, but probably not in a production environment for the long-term. Also, you could remove all the line breaks \. Not totally necessary, user preference.
    Alternatively you could use a tool such as Postman, and save collections of your API requests. I myself have been adopting this more and more and find the additional tooling useful.

    0
  • Ernest Prabhakar
    Comment actions Permalink

    Sorry if I'm missing something obvious, but how do I use an API Token with CURL?

    I have a token that works fine if I'm using one of the language APIs (in this case, Ruby).

    But if I try to use that as the "username:secret" I get:

    * Server auth using Basic with user 'robert.kinsella@nauto.com'

    ...

    < set-cookie: __cfduid=d1b530c382457412463dc1e416ffc20471574723021; expires=Wed, 25-Dec-19 23:03:41 GMT; path=/; domain=.nauto.zendesk.com; HttpOnly

    * Authentication problem. Ignoring this.

    < www-authenticate: Basic realm="Web Password"

    {"error":"Couldn't authenticate you"}*

    I even get the same error when using "Basic Authentication" on your web portal.  

    https://developer.zendesk.com/requests/new

    How am I supposed to pass in a token for these APIs?

    0
  • Charles Nadeau
    Comment actions Permalink

    Hi Ernest,

    For an API token from the Support admin interface, use this format:

    {email_address}/token:{api_token}

    where '/token' is hard-coded. Example cURL:

    -u jdoe@example.com/token:12345abcd6789

    For more info, see the dev docs - https://developer.zendesk.com/rest_api/docs/support/introduction#api-token.

    0
  • Emma Edwards
    Comment actions Permalink

    using Curl with ReqBin seems easier.

    https://reqbin.com/curl - just in case

    0
  • Anthony Yeates
    Comment actions Permalink

    We are able to successfully invoke the ZenDesk API if we login in a browser first (credentials stored in cookie presumably), however, we have been unable to access it using curl in Windows 10.  We get a 401 error - invalid credentials - even though we are using the same credentials that work in the browser.  Do we need different credentials to call the API using curl and programmatically?

    Here is the error in more detail:

     

    C:\Windows\system32>curl https://XXXXX.zendesk.com/api/v2/incremental/tickets.json?start_time=1332034771 \ -v -u XXXX@XXXXX.com:XXXXX
    * Trying 104.16.51.111...
    * TCP_NODELAY set
    * Connected to XXXXX.zendesk.com (XX.XX.XX.XXX) port 443 (#0)
    * schannel: SSL/TLS connection with XXXXX.zendesk.com port 443 (step 1/3)
    * schannel: checking server certificate revocation
    * schannel: sending initial handshake data: sending 197 bytes...
    * schannel: sent initial handshake data: sent 197 bytes
    * schannel: SSL/TLS connection with XXXXX.zendesk.com port 443 (step 2/3)
    * schannel: encrypted data got 2704
    * schannel: encrypted data buffer: offset 2704 length 4096
    * schannel: sending next handshake data: sending 93 bytes...
    * schannel: SSL/TLS connection with XXXXX.zendesk.com port 443 (step 2/3)
    * schannel: encrypted data got 258
    * schannel: encrypted data buffer: offset 258 length 4096
    * schannel: SSL/TLS handshake complete
    * schannel: SSL/TLS connection with XXXXX.zendesk.com port 443 (step 3/3)
    * schannel: stored credential handle in session cache
    * Server auth using Basic with user 'XXXX@XXXXX.com'
    > GET /api/v2/incremental/tickets.json?start_time=1332034771 HTTP/1.1
    > Host: XXXXX.zendesk.com
    > Authorization: Basic bXXXXXXXXXXXXXXXXXXXXXXXX=
    > User-Agent: curl/7.55.1
    > Accept: */*
    >
    * schannel: client wants to read 102400 bytes
    * schannel: encdata_buffer resized 103424
    * schannel: encrypted data buffer: offset 0 length 103424
    * schannel: encrypted data got 1137
    * schannel: encrypted data buffer: offset 1137 length 103424
    * schannel: decrypted data length: 1108
    * schannel: decrypted data added: 1108
    * schannel: decrypted data cached: offset 1108 length 102400
    * schannel: encrypted data buffer: offset 0 length 103424
    * schannel: decrypted data buffer: offset 1108 length 102400
    * schannel: schannel_recv cleanup
    * schannel: decrypted data returned 1108
    * schannel: decrypted data buffer: offset 0 length 102400
    < HTTP/1.1 401 Unauthorized
    < Date: Thu, 13 May 2021 16:35:25 GMT
    < Content-Type: application/json; charset=UTF-8
    < Content-Length: 37
    < Connection: keep-alive
    * Authentication problem. Ignoring this.
    < WWW-Authenticate: Basic realm="Web Password"
    < Strict-Transport-Security: max-age=31536000;
    < Cache-Control: no-cache
    < X-Zendesk-Origin-Server: classic-app-server-654cc7dd9b-k526r
    < X-Request-Id: 64ed4cc63cdd40e4-LHR
    < X-Runtime: 0.070518
    < CF-Cache-Status: DYNAMIC
    < cf-request-id: 0a082e4fe2000040e42fb9e000000001
    < Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
    < Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report?s=YhQ2uuYQFhBN14oq0hV8DTEvaMAeRKAUTRPoyLm5nDFzSZgamJJ0i08i4MOfAyU0oyhEkYjf96gnkEYtbh65g3TpO9RUVkZBEKsPs5WNkyu1dLJCASpmXnXeSblWzJxNfQ%3D%3D"}],"group":"cf-nel","max_age":604800}
    < NEL: {"report_to":"cf-nel","max_age":604800}
    < Set-Cookie: __cfruid=41ded98ceaf58bf8185b52cb4ada3df8d8b869de-1620923725; path=/; domain=.XXXXX.zendesk.com; HttpOnly; Secure; SameSite=None
    < Server: cloudflare
    < CF-RAY: 64ed4cc63cdd40e4-LHR
    <
    {"error":"Couldn't authenticate you"}* Connection #0 to host XXXXX.zendesk.com left intact
    * Rebuilt URL to: \/
    * Could not resolve host: \
    * Closing connection 1
    curl: (6) Could not resolve host: \
    0
  • Anthony Yeates
    Comment actions Permalink

    Resolved the 401 issue above as follows:

    1. Used browser to go to: https://XXXX.zendesk.com/agent/admin/api/settings

    ...where XXXXX is the name of your Zendesk.

    2. Logged in to Zendesk and turned this option on:

     

    0
  • Brett Bowser
    Comment actions Permalink

    Hey Anthony!

    Glad you were able to get this issue resolved on your end :)

    Super useful for anyone else that runs into similar issues.

    Cheers!

    0

Please sign in to leave a comment.

Powered by Zendesk