All the examples in the Zendesk REST API docs use curl, a lightweight, command-line tool for making HTTP requests without a web browser. curl lets you try out various API requests in a command-line interface such as the command prompt in Windows or Terminal in macOS. You don't need to build a working web application just to try out the APIs.

curl makes HTTP requests just like a web browser. To request a web page from the command line, type curl followed by the site's URL:

The web server's response is displayed directly in your command-line interface. If you requested an HTML page, you get the page source -- which is what a browser normally sees.

Related topic

Disclaimer: Zendesk can't provide support for third-party technologies such as curl or Windows.

Using curl

You can use curl to inspect and test different Zendesk API requests without having to build a functioning web application. For example, the following curl statement makes an HTTP request to the List Groups endpoint in the Zendesk API:

curl https://mysubdomain.zendesk.com/api/v2/groups.json \  -v -u [email protected]/token:6wiIBWbGkBMo1mRDMuVwkw1EPsNkeUj95PIz2akv

The API returns a JSON object that lists the groups in your Zendesk Support instance:

{  "groups": [    {      "name":       "DJs",      "created_at": "2009-05-13T00:07:08Z",      "updated_at": "2011-07-22T00:11:12Z",      "id":         211    },    {      "name":       "MCs",      "created_at": "2009-08-26T00:07:08Z",      "updated_at": "2010-05-13T00:07:08Z",      "id":         122    }  ]}

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It's designed to be easy for humans to read and write, and for machines to parse and generate. To learn more, see Working with JSON.

Using curl in Windows

You can use the Windows command prompt to run the curl examples. To start the command prompt, open the Start menu, type cmd in the search box, and press Enter.

By default, curl isn't installed in Windows 10, version 1803 or earlier. See Installing curl below to install it on your system.

The examples in the docs have to be modified slightly to work correctly in Windows. First, replace any line-ending backslash (\) character with the caret (^) character. Second, if an example contains JSON data, move the data to a file before running the example. The following sections give more details.

Replace line-ending backslashes

The curl examples often have a backslash (\) at the end of lines to break up a long statement into easier-to-read lines. The backslash is a line continuation character in UNIX but not in Windows. In Windows, replace any backslash at the end of lines with the caret (^) character, which is an escape character in Windows. Don't leave any space after any ^ character or it won't work. The caret will escape the space instead of the new line.

Example:

curl https://mysubdomain.zendesk.com/api/v2/groups.json ^  -v -u [email protected]/token:6wiIBWbGkBMo1mRDMuVwkw1EPsNkeUj95PIz2akv

You can paste a multiline statement at the command prompt by clicking the icon in the upper-left corner and selecting Edit > Paste. If you prefer using the keyboard, press Alt+spacebar to open the menu, then press E and P.

Move JSON data to a file

The Windows command prompt doesn't support single quotes. It's a problem because curl statements use single quotes to specify JSON data. Example:

curl https://{subdomain}.zendesk.com/api/v2/groups.json ^  -d '{"group": {"name": "My Group"}}' ^  -H "Content-Type: application/json" ^  -v -u {email_address}/token:{api_token} -X POST

The statement specifies JSON data for creating a group (the -d flag stands for data). Because the JSON is enclosed in single quotes, the statement won't work on the command line.

To fix the problem, save the JSON in a separate file and import it into the curl statement. To modify the example above, create a file named json.txt containing the following text:

{"group": {"name": "My Group"}}

Next, change the curl statement to import the JSON data with the @filename syntax:

curl https://{subdomain}.zendesk.com/api/v2/groups.json ^  -d @json.txt ^  -H "Content-Type: application/json" ^  -v -u {email_address}/token:{api_token} -X POST

Before running the statement, use the cd command (for change directory) to navigate to the folder that contains the file. Example:

C:\> cd json_files

Then paste the curl statement at the command prompt:

curl https://{subdomain}.zendesk.com/api/v2/groups.json ^  -d @json.txt ^  -H "Content-Type: application/json" ^  -v -u {email_address}/token:{api_token} -X POST

An alternative to moving the JSON to a separate file is to use double quotes around the JSON data in the curl statement and escape the inner ones with backslashes:

-d "{\"group\": {\"name\": \"My Group\"}}" \

It doesn't end there. The following special characters in strings must be escaped with the caret (^) character: &, \, <, >, ^, |. If the JSON includes HTML, such as when you try to create or update an article in the help center, you need to find and escape all the angle brackets in the HTML.

This is tedious and error prone. Best to stick with importing the JSON from a file.

Installing curl

macOS

curl is installed by default on macOS. To try it out, see Testing your curl installation below.

Windows 10, version 1803 or later

If you have version 1803 or later of Windows 10, curl is installed by default. To try it out, see Testing your curl installation below.

Windows

If you have a version of Windows earlier than Windows 10, version 1803, you can download and install curl as follows.

  1. In Windows, create a folder called curl in your C: drive.

  2. Go to https://curl.se/download.html and download one of the following zip files:

    • If you have a Windows 64 system, scroll to the Win64 - Generic section and look for the latest Win64 ia64 zip version with SSL support. It's normally second in the list. Click the version number to start the download.
    • If you have a Windows 32 system, scroll to the Win32 - Generic section and look for the latest Win32 zip version with SSL support. It's normally second in the list. Click the version number to start the download.
  3. Unzip the downloaded file and move the curl.exe file to your C:\curl folder.

  4. Go to https://curl.se/docs/caextract.html and download the digital certificate file named cacert.pem.

    The PEM file contains a bundle of valid digital certificates. The certificates are used to verify the authenticity of secure websites. They're distributed by certificate authority (CA) companies such as GlobalSign and VeriSign. The PEM file allows curl to connect securely to the Zendesk API using the Secure Sockets Layer (SSL) protocol.

  5. Move the cacert.pem file to your C:\curl folder and rename it curl-ca-bundle.crt.

  6. Add the curl folder path to your Windows PATH environment variable so that the curl command is available from any location at the command prompt. Update the variable as follows:

    1. In the Start menu, right-click This PC and select More > Properties.

      Note: In Windows 7, right-click Computer and select Properties.

    2. Click Advanced System Settings.

    3. In the Advanced tab, click the Environment Variables button on the lower right side.

    4. Select the "Path" variable in System Variables, and click Edit.

    5. In the Edit environment variable dialog box, click New and add the path to the curl.exe file. Example: C:\curl.

      Windows 7: In the Variable Value textbox, append a semicolon to the value, followed by the path to the curl.exe file. Example: ;C:\curl

    6. Keep clicking OK to accept the change and close the dialog box.

Testing your curl installation

You can test your curl installation by making a request to the Zendesk API. The test retrieves your Zendesk Support user information.

To test curl

  1. Paste the following curl statement into your favorite text editor:

    curl https://{subdomain}.zendesk.com/api/v2/users/me.json \      -v -u {email_address}/token:{api_token}

    For details on this endpoint, see Show the Currently Authenticated User in the Zendesk API docs.

    Windows users: Replace the backslash (\) line continuation character with a caret (^) character. Make sure there's no space after the caret. See Using curl in Windows above.

  2. Replace the placeholders in curly brackets with the information you use to sign in to Zendesk Support. Example:

    curl https://obscura.zendesk.com/api/v2/users/me.json \  -v -u [email protected]/token:6wiIBWbGkBMo1mRDMuVwkw1EPsNkeUj95PIz2akv
  3. Launch your command-line interface.

    • In Windows, open the Start menu, type cmd in the search box, and press Enter.
    • In macOS, double-click the Terminal application in your Applications/Utilities folder.
  4. Copy the curl statement from your text file and paste it at the command prompt.

    Windows users: After copying it to the Clipboard, select Edit > Paste from the context menu in the upper left corner of the window:

  5. Press Enter to run the curl statement.

    The console should display your Zendesk Support user information formatted as a JSON object.

    You can pretty print the results to make it easier to read. See Converting JSON to data you can understand.

Common curl flags

You'll see the following curl flags in the examples in the Zendesk REST API docs.

-H

Specifies any extra header content to include in the HTTP request. API requests that submit data to our servers typically include the data's content type. Example:

Example: -H "Content-Type: application/json".

-u

Specifies the user name and password to use for server authentication. The user name and password are separated by a colon.

Example: -u [email protected]/token:6wiIBWbGkBMo1mRDMuVwkw1EPsNkeUj95PIz2akv

-v

Makes the response more verbose.

-X

Specifies the request method to use when communicating with the HTTP server. Example: PUT or POST.

Note: GET is the default method so you don't need to specify it.

Example: -X PUT

-G --data-urlencode

Used for API endpoints that send data in a query string, such as the Search API. The --data-urlencode option url-encodes the query string. The -G flag specifies that the url-encoded data is for a GET request rather than a POST request.

For example, suppose you want to run the following search using the List Search Results endpoint:

.../api/v2/search.json?query=type:ticket status:open

The curl command looks like this:

curl "https://{subdomain}.zendesk.com/api/v2/search.json" \  -G --data-urlencode "query=type:ticket status:open" \  -v -u {email_address}/token:{api_token}