Skip to content

Instantly share code, notes, and snippets.

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://{}{}/attachments.json".format(SUBDOMAIN, article_id)
# url = ""
r =, files=files)
if (r.status_code == 201):
return r.json()
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