Improving performance by creating tickets asynchronously

If you create tickets in Zendesk Support with the API but want faster response times in your application, you can instruct the API to queue the jobs and just return a ticket ID and information about the status of the job.

You enable this option by adding an async=true query string parameter to the Create Ticket endpoint URL. Example:

curl https://{subdomain}.zendesk.com/api/v2/tickets.json?async=true \  -d '{"ticket": ... }' \  -H "Content-Type: application/json" \  -v -u {email_address}/token:{api_token} -X POST

The quicker response will contain the id of the ticket to be created as well as a job_status object that you can inspect. The response won't contain any other ticket information.

Creating tickets takes a long time because the system has to run each ticket through all your triggers and save data to a database before it knows what the full response looks like.

You won't be able to fetch the ticket until the job is done. There's a possibility the background job will fail and the ticket won't be created. To ensure the ticket was created, check to see if the job status is "completed", or if the ticket exists.

To check the job status

  1. Retrieve the job status id from the response to the asynchronous request.

  2. Use the status id to make a request to the Show Job Status endpoint:

    curl https://{subdomain}.zendesk.com/api/v2/job_statuses/{id}.json \-v -u {email_address}/token:{api_token}
  3. Verify the status property in the response.

    The status can be one of the following: "queued", "working", "failed", "completed", or "killed".

To check if the ticket exists

  1. Retrieve the job status id from the response to the asynchronous request.

  2. Use the ticket id to make a request to the Show Ticket endpoint:

    curl https://{subdomain}.zendesk.com/api/v2/tickets/{id}.json \  -v -u {email_address}/token:{api_token}
  3. Verify the response.

    If the ticket was successfully created, you'll get the full ticket response back. If it hasn't been created yet, or if it failed to be created, you'll get a 404 Not Found error.