亚博Zendesk API快速start

In this 10-minute quick start, you'll use the Zendesk Ticketing API to create a few tickets in Zendesk Support.

The tutorial is intended for admins and agents with no developer experience. To make the API requests, the tutorial uses your web browser's built-in JavaScript console.

If you're a more experienced developer, check out theAPI reference. The reference includes curl examples for each endpoint. The API reference also includes links to related Postman collections. SeeExploring Zendesk APIs with Postman.

What you'll need

To complete this tutorial, you'll need the following:

Creating tickets

To create a ticket, use the JavaScript console to make an HTTP POST request to the Ticketing API'sCreate Ticketendpoint.

  1. Sign in to your Zendesk account as an admin or agent. From the Zendesk Agent Workspace, open your browser's JavaScript console:

    • Chrome:View>Developer>JavaScript Console
    • Firefox:Tools>Browser Tools>Web Developer Tools. Then click theConsoletab.
    • Safari:Develop>Show JavaScript Console
    • Microsoft Edge:Tools>Developer>JavaScript Console
  2. Paste the following script into your browser's console.

                   
    for(leti=1;i<4;i++){constsubject=`Test ticket${i}`constbody=`This is test ticket${i}`$.ajax({url:"/api/v2/tickets.json",contentType:"application/json",type:"POST",data:JSON.stringify({ticket:{subject:subject,comment:{body:body}}})}).done(data=>{console.log(data.ticket)})}

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

    The code snippet creates a loop that makes three requests to the Create Ticket endpoint. Each request creates a ticket in Zendesk Support.

  3. Press Enter.

    If successful, the console lists the tickets as JavaScript objects.

    You can expand each object to see the ticket's properties.

  4. To view the tickets in the Agent Workspace, reload the browser tab. Then clickViews>Recently updated tickets.

    When you're done trying out the API, delete the test tickets by selecting them in the list and clicking删除.

Troubleshooting tips

If the script returned an error, try the following troubleshooting tips:

  • If you get a 404 (Not Found) response, sign in to your Zendesk account before running the script.

  • If you get aTypeError: $.ajax not a functionerror, ensure you run the script from the Agent Workspace in Zendesk Support.

  • If you get a JavaScript error indicating that$.ajaxis not defined, ensure you don't have any browser settings or plugins that block scripts from loading.

Next steps

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

  • To see what's possible using Zendesk APIs, check out theAPI reference.

  • Use Postman to explore the Zendesk APIs. Postman is a popular application for testing APIs and making API requests. SeeExploring Zendesk APIs with Postman.

  • Install curl to run example requests from the API reference documentation. curl is a command-line tool for making HTTP requests without a web browser. SeeInstalling and using curl.

  • Speed up development with anAPI 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.

  • Learn about themost common tasksdevelopers perform with the Ticketing API.

  • Ask questions or look for answers in theZendesk APIs community.