Skip to content

Instantly share code, notes, and snippets.

@dpawluk
Last active April 17, 2017 17:34
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dpawluk/58d9c06dd1c98aca5f7c52e317311c75 to your computer and use it in GitHub Desktop.
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