Creating a ticket in Zendesk Support

When an end user is chatting with your bot outside opening hours, it can be useful to design a flow that allows them to leave a message. That way, the human agents may respond to user requests when they are next available.

If you have a Zendesk Support subscription, you can accomplish this with our wh_iconZendesk Support Create Ticket Webhook Template, which we'll describe below. No Zendesk Support subscription? Try our wh_iconCertainly Dynamic Email Notification Webhook Template.

Need more info on Webhook data formatting and processing? Check out our article on configuring Webhooks - we recommend resources on JSON and Jinja as well.

In this article, we'll share a helpful video and address authentication, common configurations of the wh_iconZendesk Support Create Ticket Webhook Template, and how to test the Webhook.

Video tutorial

For a step-by-step approach to ticket creation in Zendesk Support, please refer to this video:

Authentication

This Webhook requires authentication. We recommend using an API token generated in Zendesk. API tokens are managed in the Admin Center interface. Navigate to Apps and integrations > APIs > Zendesk API.

In the Authentication section of the Webhook, insert the API token into the password field and {email_address}/token into the user name field. Note that {email_address} is the email address of the person who generated the API token.

You can find additional details in Zendesk's article on API security and authentication.

Simple ticket

Usually a Zendesk ticket contains the description of the problem as well as the name and email of the user. For that, you'll need to build a flow that collects this data and stores it in CVars.
Let's assume these three variables are visitor_name, visitor_email, and visitor_message. The simple body of the Webhook will look like this:
{
  "ticket": {
    "requester": {
    "name": "{{visitor_name}}",
    "email": "{{visitor_email}}"
    },
    "subject": "Ticket automatically created from Certainly",
    "priority": "normal",
    "type": "task",
    "comment": {
      "public": true,
    "body": {{visitor_message | tojson}}
    }
  }
}
  • "requester" - Object that identifies the user. If omitted, the ticket will be created on behalf of the user used in Authentication. If the user exists in Zendesk, only "email" is required, and all other fields in the "requester" object will be ignored. For a new user, the "email" and "name" fields are required, and you can also add a "phone" field for the phone number. Zendesk will create a new user record with all the information provided. 
  • "priority" - Valid values are: "urgent", "high", "normal", or "low".
  • "type" - Valid values are: "problem", "incident", "question", or "task".
  • "comment" - User's message. It can be public ("public": true) or internal ("public": false). The actual message can be passed as a text via the "body" field or as HTML via an "html_body" field. We recommend using {{visitor_message | tojson}} syntax (note there are no double quotes) instead of "{{visitor_message}}" as it ensures the JSON body is not broken if {{visitor_message}} has newline or other special characters.

More details can be found in Zendesk's article on API ticket creation.

Ticket with tags, form ID, and custom fields

While the previous Webhook body is good for training and simple tickets, we often need to address other Zendesk features such as tags, custom fields, and forms. The ticket description also usually contains a few lines.
Below is an example body demonstrating the use of all these features.
{
  "ticket": {
    "requester": {
    "name": "{{visitor_name}}",
    "email": "{{visitor_email}}"
    },
    "subject": "Ticket automatically created from Certainly",
    "priority": "normal",
    "type": "task",
    "comment": {
      "public": true,
    "body": {{("Message1 : " ~ visitor_message1 ~
"Message2 : " ~ visitor_message2) | tojson}}
  },
"tags": ["certainly_chatbot", "{{dynamic_tag}}"],
"ticket_form_id": 360003653593,
"custom_fields": [{"id": 360007562940, "value": "Field value"}]
  }
}
  • "tags": ["certainly_chatbot", "{{userTag}}"] - Creates two tags for the ticket. The first tag is "certainly_chatbot" and the second one is the value of the CVar dynamic_tag. If the variable is an empty string "", the second tag is ignored.
  • "ticket_form_id": 360003653593 - Zendesk's form ID. Note that this is an integer, without double quotes. If you don't use forms, simply delete this line. An Enterprise-level Zendesk Support subscription is required to use forms.
  • "custom_fields": [{"id": 360007562940, "value": "Field value"}] - Custom field ID and its value. You can only refer to the custom field by its number. You can find it in the Zendesk field configuration. If you need to pass more than one field, use the following syntax: [{"id": 1, "value": "fv1"},{"id": 2, "value": "fv2"}]. Note that the "drop-down list", "checkbox", and "multi-select" custom fields automatically add tags.

For more information about the different types of custom fields, please refer to Zendesk's documentation on setting custom field values.

Ticket with chat transcript and HTML comment

This configuration assumes you call the wh_iconCertainly Get Conversation History Webhook prior, so the CVar chatHistory contains the transcript of the chat. It also uses "html_body" for rich formatting of the ticket's comment.

This is the recommended default body for the Webhook.

{
  "ticket": {
    "requester": {
    "name": "{{visitor_name}}",
    "email": "{{visitor_email}}"
    },
    "subject" : "Ticket created from a conversation with Certainly",
    "priority" : "normal",
    "type" : "task",
    "comment": {
      "html_body": {%- if chatHistory is defined and chatHistory!= "" -%}
                {{chatHistory|replace("[Human]","<br><b>[Human]</b>")|replace("[Bot]","<br><b>[Bot]</b>")|tojson}}
              {%- else -%}
              "Full conversation with the chatbot https://app.certainly.io/inbox/{{certainly.botId}}/{{certainly.sessionId}}"
              {%- endif %},
      "public": false
    },
  "tags": ["created_by_certainly", "handed_over_by_certainly"]
  }
}

Adding more comments to the ticket

Sometimes you may need to add another comment to the ticket or split one comment in two.

For this case, use the  wh_iconZendesk Support Update Ticket Webhook. You'll need to call it after wh_iconZendesk Support Create Ticket so the zendesk_ticket_id and zendesk_requester_id CVars are populated with proper values. In the body of the Webhook, you can specify the visibility of the comment (public or internal) and the status of the ticket (open, solved, and so on).

Testing the Webhook

To quickly test the Webhook inside the Certainly Platform, you can follow these steps:
  1. Save the Webhook.
  2. Replace all CVars in the parameters and body with values. For example, replace the CVar "visitor_email" with "test@test.com".
  3. Select Run. The response should appear and the zendesk_ticket_id CVar should be populated with the number of the ticket.

Have any questions? Just reach out to our Customer Success team.