Zendesk API quick start

In this 10-minute quickstart, you'll use the Zendesk API to create a few tickets.

To keep things moving along, you'll use the JavaScript console of your browser to make the API requests.

To authenticate the requests, you simply need to be signed in to your Zendesk Support account as an agent or admin on the same page as the JavaScript console.

This quickstart tutorial is meant to introduce you to the Zendesk API.

Preparation

  1. If you don't already have a Zendesk Support account, register to start a free trial at https://www.zendesk.com/register/

  2. In your browser, navigate to your Zendesk account. The url will look something like https://your_subdomain.zendesk.com.

  3. In Admin Center, click the Apps and integrations icon () in the sidebar, then select APIs > Zendesk APIs. Under the Settings tab, make sure Password Access is enabled in the settings. If you don't have permissions to do this, ask an admin to check for you.

  4. Make sure you're still in the agent interface, then open the browser's JavaScript console on the same page, as follows:

    • Chrome: View > Developer > JavaScript Console
    • Firefox: Tools > Web Developer > Web Console
    • Safari: Develop > Show JavaScript Console. If you don't see the Develop menu, you'll need to turn it on in Safari preferences (Safari > Preferences, and click the Advanced tab).

    It's important to open the console on the agent interface page or your API requests won't work.

Create some tickets

Let's create 3 tickets with one code snippet. To create a ticket with the API, you make a POST request to the /api/v2/tickets.json endpoint. You can find all the details about the Tickets API in the developer docs, but for now let's jump right in.

  1. Paste the following script into your browser's console:

    for(x=0; x<3; x++) {  var subject = "Test ticket #" + x;  var body = "This is test ticket #" + x;  $.ajax({    url: '/api/v2/tickets.json',    contentType:'application/json',    type: 'POST',    data: JSON.stringify({"ticket": {"subject": subject , "comment": { "body": body }}})  })  .done(function(data) {    console.log(data.ticket);  });}

    Here's what the code looks like after pasting it in the console in Google Chrome:

    The code snippet creates a loop that makes 3 API requests.

  2. Hit Enter.

    Trouble?

    • If you get POST https://subdomain.zendesk.com/api/v2/tickets.json 404 (Not Found), it means you're not currently signed in to your account. Go do that now and retry.
    • If you get a TypeError: $.ajax not a function, it means you're not currently on the agent interface page. Open the agent interface, then open the JavaScript console on the same page, and give it another shot.
    • If you get a JavaScript error that Ajax is not defined, make sure you don't have any browser settings or plugins that block scripts from loading.
  3. If successful, you'll see the new tickets listed as objects in the console:

    The last 3 objects are new tickets and all their information, including a bunch of properties you didn't bother to set. In the Chrome example above, you'd click the expander icon on the left of each object to see the rest of the properties.

    Check out the properties you set yourself (description and subject), and ones the system set for you, such as status. If you'd been so inclined, you could have set the ticket status yourself. Example:

    data: JSON.stringify({"ticket": {"subject": subject , "status": "open", "comment": { "body": body }}})
  4. Switch to the agent interface to view your new tickets (click Views then Unassigned tickets):

When you're done trying out the API, delete the test tickets by selecting them in the list, clicking the Edit Tickets button in the upper-right, and selecting Delete.

Next steps

The best way to learn how to use the Zendesk API is to try different requests on your own. You can use any of the following resources along the way:

  • Learn about the most common tasks developers perform with the Zendesk API

  • Peruse the extensive API reference documentation on the Zendesk developer portal

  • Run any of the examples in the reference docs using curl, a lightweight, command-line tool for making HTTP requests without a web browser. See Installing and using curl

  • Speed up development with an API client. An API client takes care of a lot of the low-level details of making requests and handling responses and lets you focus on the logic of your application

  • Ask questions or look for answers in the Zendesk APIs community.