Python + Zendesk: A Dynamic Duo for Customer Support Innovation

Tanvi
Simform Engineering
6 min readFeb 13, 2024

Zendesk integration in Python facilitates seamless communication between Python applications and Zendesk’s customer service platform.

Imagine a scenario where a company is bombarded with customer inquiries coming in through diverse channels like phone calls, emails, social media messages, and even handwritten letters. Each inquiry is manually written down on paper and stored in filing cabinets. Support agents spend hours daily sifting through these records to organize and assign tasks.

Without a ticketing system, some of these customer problems may end up being overlooked, causing delays and leaving customers unsatisfied. Coordinating the efforts of support agents becomes quite challenging as there is no method to keep track of who’s handling which task.

Moreover, accessing historical customer data can be quite a task since we don’t have a database. Our agents have to search through stacks of paper to find interactions, which makes it harder for us to offer personalized support.

In this challenging environment, can you envision a solution that streamlines customer support, improves response time, and enhances customer satisfaction? The answer lies in CRM software such as Zendesk, which offers a modern, efficient, and centralized approach to managing customer inquiries and support operations. With Zendesk, you can transform this chaotic scenario into a well-organized and customer-centric support system.

Let’s see how!

What is Zendesk and how does it work?

Zendesk support, at its core, is a help desk system. It enables enterprises to receive and oversee customer inquiries, support appeals, and service tickets. The platform offers a ticketing mechanism to address customer queries where each ticket represents a customer inquiry and any issues or problems faced.

It brings together customer inquiries from communication channels like chat, phone, email, and social media. This creates a platform for organizing, managing, and resolving issues.

Centralized system managing customers across various channels

Now, you might be wondering who resolves the tickets that are created by the customers. So for that, they have classified the users into two types viz :

→ Internal: Your agents and other support staff who resolve the tickets.

→ External: The customers to whom you provide support and whose tickets you manage in Zendesk support.

Depending on the type of support you want to provide, you can set up your Zendesk support access to be completely open to all external users (categorized as OPEN), restrict it to a specific group or groups of external users (categorized as RESTRICTED), or close your Zendesk Support instance and allow only the external users you add to your Zendesk account (categorized as CLOSE).

Let’s get started with the integration

Let’s dive into how to create, retrieve, update, and delete tickets on Zendesk using Python.

First, you need to create a Zendesk account and save the API key, as shown below.

Go to the Dashboard of your Zendesk account → spot the four small squares on the top right → Go to Admin center → Click Apps and Integrations on the left side → Click on Zendesk API → Agree on the terms → Click on Settings → Enable both the fields → Click on Add API token → Click on copy and paste this token somewhere else for future use → After copying it, click on Save.

NOTE: The API key will only be displayed once while creating the account, so you need to save it somewhere else because that will be used to perform further operations.

There are two ways to perform the CRUD operations:

  • Using the Zendesk API
  • Using Python SDK, i.e., Zenpy ( a Python client for Zendesk Support developed by Facetoe, and it is also available using pip. It's a Python wrapper for Zendesk API).

You can check the documentation of the Zenpy here: http://docs.facetoe.com.au/

Creating the ticket using Zenpy

Subdomain: https://your_subdomain.zendesk.com/admin/home

The placeholders used in place of ‘your_subdomain’ in the previous line represent your subdomain.

Note: Do not include ‘zendesk.com’ in your subdomain.


from zenpy import Zenpy
from zenpy.lib.api_objects import Ticket

subdomain = 'your subdomain' # can get this from your zendesk url
email = 'your email address'
api_token = 'your api token' # saved token you just created above
password = 'your password of zendesk account'

zendesk = Zenpy(subdomain=subdomain, email=email, token=api_token)
ticket_id = 0 #Assigning this as '0' because we will change it later on.


def create_ticket(request):
global ticket_id
new_ticket = zendesk.tickets.create(
Ticket(
subject='creating my first ticket',
description='No description for the first ticket')
)

ticket_info = new_ticket.to_dict()
ticket_id = ticket_info.get('audit').get('ticket_id')
print("Ticket created successfully ")

See the image below to validate ticket creation:

You can view all your tickets generated by clicking the profile icon → View profile.

Updating the ticket using API

import json
import requests

def update_ticket(request):
global ticket_id
# Ticket to update
ticket_id = str(ticket_id)
body = 'Updating the ticket.'

data = {'ticket': {'comment': {'body': body}}}
payload = json.dumps(data)

url = 'https://your subdomain.zendesk.com/api/v2/tickets/' + ticket_id + '.json'
user = 'your email address'
pwd = 'your password of zendesk account'
headers = {'content-type': 'application/json'}

response = requests.put(url, data=payload, auth=(user, pwd), headers=headers)

if response.status_code != 200:
print('Status:', response.status_code, 'Problem with the request. Exiting.')
exit()

print('Successfully added comment to ticket #{}'.format(ticket_id))
return HttpResponse("Ticket updated successfully !! ")

You can see the updated ticket below:

Make sure that you are passing the ticket_id of the ticket that you want to update.

Retrieving all the tickets using the API

def retrieve(request):
import requests

url = "https://your_subdomain.zendesk.com/api/v2/tickets"

headers = {
"Content-Type": "application/json",
}

response = requests.request(
"GET",
url,
auth=('your email', 'your password '),
headers=headers
)

print(response.text)
return HttpResponse("Ticket retrieved successfully !! ")

Deleting the ticket using API

import requests

url = "https://your_subdomain.zendesk.com/api/v2/tickets/123456"
headers = {
"Content-Type": "application/json",
}

response = requests.request(
"DELETE",
url,
auth=('your email', 'your password'),
headers=headers
)

print(response.text)

Advantages of Zendesk:

  • Integration with third-party applications and systems is smooth and seamless.
  • Multilingual support.
  • Easy tracking of customer interactions efficiently across channels and departments.
  • They have streamlined the team setup process on our platform, making it easier for you to generate leads and provide customer service all in one place.
  • Robust reporting and analytics capabilities.
  • A comprehensive platform for generating leads and managing customer service.
  • Various means of communication, such as chat, phone calls, email, and social media platforms.
  • Offers abundant customization possibilities. 

Disadvantages of Zendesk:

  • Advanced support features are exclusive to higher-priced tiers.
  • It might not be a good option for handling tickets in e-commerce and small businesses.
  • Requires a commitment to acquire knowledge and adjust to the software.
  • Integration options are somewhat limited when it comes to using e-commerce platforms like Shopify, Magento, or BigCommerce.
  • Possibly comes with a steep cost and complicated pricing structures.
  • The user interface lacks intuitiveness and customization options.

Conclusion

To put it simply, the integration of Python with Zendesk can revolutionize customer support and service operations. This powerful combination harnesses the flexibility of Python and the advanced capabilities of Zendesk to improve efficiency and ensure customer satisfaction.

By incorporating Python scripts and utilizing Zendesk APIs, you can personalize your support procedures. From automating ticket generation to conducting data analysis, there are opportunities to optimize efficiency and allocate resources effectively, all while providing customized experiences for your customers.

Resources:

Zendesk API reference: https://developer.zendesk.com/api-reference/

For more updates on the latest tools and technologies, follow the Simform Engineering blog.

Follow us: Twitter | LinkedIn

--

--