Last active
June 17, 2016 19:14
-
-
Save dpawluk/3140cc64966b9d09741a3417fd87541b to your computer and use it in GitHub Desktop.
Upload a file to help center article using Python Requests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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