Skip to content

Instantly share code, notes, and snippets.

@msnriggs
Forked from Nick011/Perch API: Python Demo
Created June 28, 2019 13:16
Show Gist options
  • Save msnriggs/0fe74c4a465b9102164c15eff21c0515 to your computer and use it in GitHub Desktop.
Save msnriggs/0fe74c4a465b9102164c15eff21c0515 to your computer and use it in GitHub Desktop.
# 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