-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_template.py
43 lines (35 loc) · 1.38 KB
/
get_template.py
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
43
############ IMPORTS ############
import requests
import time
import json
from pprint import pprint
import certifi
import urllib3 # docs: https://urllib3.readthedocs.io/en/latest/index.html
http = urllib3.PoolManager( # 10 is default, can be increased if needed
cert_reqs='CERT_REQUIRED', # docs: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
ca_certs=certifi.where())
############ PARAMETERS ############
company = "yourCompany" #
key = "yourKey" # API key
action = "desk/v1/yourEndpoint/" # define endpoint(see: http://deskdeveloper.teamwork.com/desk)
############ GET REQUEST ############
url = "https://{0}.teamwork.com/{1}".format(company, action) # create our URL with defined parameters above
headers = urllib3.util.make_headers(basic_auth=key + ":xxx") # authorize request using basic http auth
request = http.request('GET', url, headers=headers) # make GET request with auth header and URL parameters
response = request.status # capture return value in response
# View status and catch errors
if response == 200:
print('Success! Status of: ')
print(response)
elif response == 404:
print('Not Found. Status of: ')
print(response)
else:
print('Error occurred. returned status of: ')
print(response)
print(request.headers)
print()
############ CONSUME REQUEST ############
binary = request.data
output = json.loads(binary)
pprint(output)