Last active
June 28, 2019 13:16
-
-
Save Nick011/f4e952abf6ccbf811cd6e0241c8a220a to your computer and use it in GitHub Desktop.
This file contains 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
# Setup | |
import requests | |
api_key = 'apyvBhYVkl4li2QEajBhV6MwgNv1UT1w7M6W5jpX' | |
username = 'api-a68a23fdc61b4b9ab39ccd3633bf5e6b' | |
password = '(Your API Password)' | |
header = { | |
'x-api-key': api_key | |
} | |
base_url = 'https://api.perch.rocks/v1' | |
auth_url = base_url + '/auth/access_token' | |
alerts_url = base_url + '/alerts' | |
# Authenticate the user and set the auth token header | |
req_body = { | |
'username': username, | |
'password': password | |
} | |
res = requests.post(auth_url, data=req_body, headers=header) | |
res.status_code | |
res_body = res.json() | |
header['Authorization'] = 'Bearer ' + res_body['access_token'] | |
# Request all alerts for your company | |
res = requests.get(alerts_url, headers=header) | |
res.status_code | |
res_body = res.json() | |
# Request all the open alerts | |
open_alerts_url = alerts_url + '?closed=False' | |
res = requests.get(open_alerts_url, headers=header) | |
res.status_code | |
res_body = res.json() | |
res_body['results'][0] | |
# Request all the closed alerts | |
closed_alerts_url = alerts_url + '?closed=True' | |
res = requests.get(closed_alerts_url, headers=header) | |
res_body = res.json() | |
res_body['results'][0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment