Recent searches


No recent searches

Making requests to the Zendesk API



Posted Mar 17, 2021

This is a continuing discussion about the article Making requests to the Zendesk API in the developer documentation.


0

10

10 comments

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:

curl -u <usrname:pass> https://<subdomain>..zendesk.com/api/v2/help_center/articles/115005591108/attachments.json -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>.zendesk.com/api/v2/help_center/articles/attachments'
user = <email>
pwd = <apikey>
headers = {'content-type': 'application/json'}

# Do the HTTP post request
response = requests.post(url, 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.')
    exit()

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

 

0


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.

0


image avatar

Daniel Pawluk

Zendesk Developer Advocacy

@Kevin,

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

0


image avatar

Charles Nadeau

Zendesk Documentation Team

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) -

https://help.zendesk.com/hc/en-us/articles/229136927-Searching-with-the-Zendesk-API#python

HC search API

https://developer.zendesk.com/rest_api/docs/help_center/search

Charles

0


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

0


Hello 👋 Zendesk Community! I am new to the Zendesk API and could use your help. For whatever reason I continue to receive a 401 error when I try to authenticate to our sandbox account. I have tried authenticating both using an API token and the email and password method. Both are enabled in Zendesk. 

In my instance I am trying to pull down the user data via request.get. Can anyone spot what's going on? I've even tried to copy paste the python example in this article and modify where necessary... 

Thanks in advance! 

0


Hi Tomasz -- since this is a sandbox instance, users (and related info such as passwords, etc) would need to be recreated in the sandbox. Sandboxes are completely separate instances than the "production" instance. Perhaps this particular user and password are different in the sandbox?? Just guessing here.

If the user and password are accurate for the sandbox instance, please submit a ticket to support@zendesk.com. It may require more details and access to your account that just can't be done over a community conversation. Thanks!

0


How can i connect to zendesk chat api using python???

0


Hello @...

How you call Chat REST APIs in Python would be similar to the approach mentioned above.

You'll notice, however, that Zendesk Chat APIs are prefixed with https://www.zopim.com -- there is no account subdomain like there is when calling Zendesk Support APIs.

To make API calls, you'll need to generate a Chat OAuth access token and pass that along with your API call in an Authorization header.

Check out these links for more details:

OAuth access token

OAuth authentication

Chat API tutorial: Generating an OAuth token

 

0


Hi Gil. In general to make API calls, successfully accessing the API admin page at Admin > Channels/API in Zendesk Support is needed to make sure there are no issues and the account is ready to accept API calls. Two of the three ways of authenticating an API call also require "Password enabled" turned on from that page (see How can I authenticate API requests?). There's no way around these.

I'm not sure if that answers the question. If not, reply back with the API that you're calling and the exact approach you're taking to authenticate. Also, feel free to contact Zendesk Customer Support. There may be more account specific things that need to be considered to get you going, too.

0


Please sign in to leave a comment.

Didn't find what you're looking for?

New post