Skip to content

Instantly share code, notes, and snippets.

@dpawluk
Last active June 17, 2016 19:14
Show Gist options
  • Select an option

  • Save dpawluk/3140cc64966b9d09741a3417fd87541b to your computer and use it in GitHub Desktop.

Select an option

Save dpawluk/3140cc64966b9d09741a3417fd87541b to your computer and use it in GitHub Desktop.
Upload a file to help center article using Python Requests
import requests
import json
SUBDOMAIN = 'SUBDOMAIN'
s = requests.Session()
s.auth = ('email@domain/token','VERYSECRETAPITOKEN')
def upload_attachment(article_id, path):
filename = "test.jpg" #What we want to name the file
files = {'file': (filename, open(path, 'rb'), 'image/jpeg')}
url = "https://{}.zendesk.com/api/v2/help_center/articles/{}/attachments.json".format(SUBDOMAIN, article_id)
r = s.post(url, files=files)
print(r.status_code)
print(r.text)
test = upload_attachment(000000000, 'PATH/TO/FILE/test.jpg') # Article ID and path to file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment