Installing and using cURL

Have more questions? Submit a request

10 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

    1
  • 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

Please sign in to leave a comment.

Powered by Zendesk