-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcreate_issue_with_attachment.py
More file actions
42 lines (34 loc) · 1.46 KB
/
create_issue_with_attachment.py
File metadata and controls
42 lines (34 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import json
import requests
import mimetypes
DOMAIN = "<DOMAIN>"
API_KEY = "<API_KEY>"
ATTACHMENT_FILE_PATH = "<ATTACHMENT FILE PATH>"
TEST_PAYLOAD = {"email": "test@mail.com",
"message-body": "Attachments Demo",
"title": "Test issue title",
"tags": json.dumps(["foo"]),
"meta": json.dumps({"test": 1}),
"author-name": "Test author",
"platform-type": "web",
"app-id": "random_app_20140423095931205-caae76e3be13ef6"}
def construct_attachment_object(attachment_url):
file_name = attachment_url.split("/")[-1]
file_type, encoding = mimetypes.guess_type(attachment_url)
return {"attachment": (file_name,
open(attachment_url, "rb"),
file_type)}
def make_api_call(api_endpoint, api_key, payload, attachment={}):
response = requests.post(api_endpoint,
auth=(api_key, ""),
data=payload,
files=attachment)
print "API response status {0}".format(response.status_code)
print "API response {0}".format(response.json())
if __name__ == "__main__":
api_endpoint = 'https://api.helpshift.com/v1/{0}/issues'.format(DOMAIN)
attachment_object = construct_attachment_object(ATTACHMENT_FILE_PATH)
make_api_call(api_endpoint,
API_KEY,
TEST_PAYLOAD,
attachment_object)