Making requests to the Zendesk API

Have more questions? Submit a request


  • Jeremiah Currier


  • DeVaris Brown

    We also have a blog post,, detailing how to make calls to the Zendesk API using Python. And if you anyone wants to use a Python client library check it out on Github, Good work Charles!

  • Gopi Natha

    Its simply awesome.thanks a ton.........:)

  • Kelsey Hales

    Hey guys,

    So I've been playing around with this with the end goal of figuring out how to pull large amounts of data from Zendesk so we can line it up with out in-house data for analysis. I'm a bit of a newbie, and can't figure out what's wrong. I've run the `` script and feel like I've got a handle on what it's doing, but when I try to modify it to see if I can make it work on something similar without the training wheels, I'm getting this error.
    Traceback (most recent call last):
    File "C:\Python34\", line 25, in
    form_list = data['ticket_forms']
    KeyError: 'ticket_forms'

    Here's my script, without all the url, user, pwd variable setup at the beginning.
    form_list = data['ticket_forms']
    for name in form_list:

    So it sounds like it's not reading the `ticket_forms` json correctly, and not sure what I'm doing wrong there. I've reviewed [Ticket forms doc]( and the key is ticket_forms right?

  • Angelica Coleman

    Hey Kelsey,

    Make sure you change your URL to:
    url = ''


  • Chris Berns

    I am writing a script that will go through users and use the name field to populate two user-custom fields, first and last name. I can get the user info, I run it through my python script but when I try to do a series of PUTs to update I always get a 401 error. I make a session after I do the initial GET of all of the user data. I am assuming if I have permission to get all users it isnt an Auth issue. I am incredibly new to REST and have a hard time debuggin

  • Charles Nadeau


    Are you authenticating as an agent? Agents can update the user records of end-users, but not of agents or administrators. Only administrators can update the records of all users. (The same rule applies in the Zendesk admin interface.)

  • Eco Willson

    Can you share a way to use a token for authentication instead of password?

  • Charles Nadeau

    Good idea, Eco. I added the following below the get_groups script.

    > You can use an API token instead of a password to make API requests. Grab an API token from the Zendesk Admin interface at Admin > Channels > API. To use the token in the script, append the string '/token' (not the actual token value) to your email address in the user variable and assign the token value to the pwd variable, as follows:

    >user = 'your_email_address' + '/token'
    >pwd = 'your_api_token'

  • Eco Willson

    Thanks Charles works perfectly.

  • Deron Fuller

    I thought I would add a comment for anyone doing this from an Ubuntu (or other linux distro) where you more than likely have 2 versions of python. To get the 'requests' library for python3 this is what I did:

    sudo apt-get install python3-pip
    pip3 install requests

    The instructions here indicate to just use pip, but if you're system does have 2 versions, you'll need to use pip3 to work with python3.


  • Luckyddurand

    Charles, thanks for the article. I began to study Python. Very useful to me such knowledge and experience as you have.

  • Nathaniel Erlandson

    Thanks a lot for this tutorial @Charles, helped a ton in getting me started

  • Kevin Lamenzo

    Could use some help translating a Help Center create attachment request from CURL into Python. Speficially, the -F tags in the CURL statement are throwing me off. I also tried GETing and attachment, then recreating the JSON object returned as my payload for the post, but I'm getting back a 500 error.

    I took my subdomain, usr/pass out of the snippets below.


    curl -u <usrname:pass> https://<subdomain> -F "inline=true" -F "file=@635564" -v -X POST

    Python (I copied the example above to create a ticket and tweaked it for posting an article attachment in HC):

    import requests

    # Package the data in a dictionary matching the expected JSON
    data = {"article_id": 115005591108, "display_file_name": "635564", "file_name": "635564", "inline": 'true'}
    data2 = {"article_id": 115005591108}

    # Encode the data to create a JSON payload
    payload = json.dumps(data)

    # Set the request parameters
    url = 'https://<subdomain>'
    user = <email>
    pwd = <apikey>
    headers = {'content-type': 'application/json'}

    # Do the HTTP post request
    response =, data=payload, auth=(user, pwd), headers=headers)

    # Check for HTTP codes other than 201 (Created)
    if response.status_code != 201:
        print('Status:', response.status_code, 'Problem with the request. Exiting.')

    # Report success
    print('Successfully created the ticket.')

  • Daniel Pawluk


    Here is a gist I created that should help you with the python. Let me know how it works for you.

  • Jaimin Patel

    Is there any way to query article (Help Center) docs using python? Sample/example documentation would be helpful. 

  • Charles Nadeau

    Hi Jaimin,

    You can combine the info in the article about searching tickets with Python with the API doc on searching the Help Center. The Python is the same in both cases -- just the query parameters and response attributes are different.

    How to search with Python (tickets example) -

    HC search API






  • Linde Skinner

    Hello Zendesk - as we prepare for GDPR, can you provide the specific API calls that will allow us to close accounts and scrub user information from tickets? We don't store values for any users who may submit a ticket therefore we want to query Zendesk based on a metric like email addresses.

    Thank you, Linde

  • Abdelhakim Salama

    how can i Make a requests to the Zendesk API with javascript !!! , can you shar with me an exemple !!

  • Joseph May

    Hi Abdelhakim-

    I would suggest starting here in this article, which will introduce you to making these calls in the browser console.

  • Abdelhakim Salama

    thank you


Please sign in to leave a comment.

Powered by Zendesk