Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Upload an attachment to a Help Center article
import requests
SUBDOMAIN = 'subdomain'
s = requests.Session()
s.auth = ('email@domain/token','VERYSECRETTOKEN')
def upload_attachment(article_id, path):
filename = "test.png"
files = {'file': (filename, open(path, 'rb'), 'image/png')}
url = "https://{}.zendesk.com/api/v2/help_center/articles/{}/attachments.json".format(SUBDOMAIN, article_id)
# url = "http://requestb.in/xv4t5zxv"
r = s.post(url, files=files)
if (r.status_code == 201):
return r.json()
else:
print("didn't work")
#normally a try catch instead of this is better but wanted to do it faster for example.
test = upload_attachment(221478747, '/path/to/file/test.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment