-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patheventsapi.py
More file actions
44 lines (35 loc) · 1.34 KB
/
eventsapi.py
File metadata and controls
44 lines (35 loc) · 1.34 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
43
44
import datetime
import requests
import os
# For more information, check out our support page
# https://support.1password.com/events-reporting
api_token = os.environ['EVENTS_API_TOKEN']
url = "https://events.1password.com"
start_time = datetime.datetime.now() - datetime.timedelta(hours=24)
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_token}"
}
payload = {
"limit": 20,
"start_time": start_time.astimezone().replace(microsecond=0).isoformat()
}
# Alternatively, use the cursor returned from previous responses to get any new events
# payload = { "cursor": cursor }
r = requests.post(f"{url}/api/v1/signinattempts", headers=headers, json=payload)
if (r.status_code == requests.codes.ok):
print(r.json())
else:
print("Error getting sign in attempts: status code", r.status_code)
r = requests.post(f"{url}/api/v1/itemusages", headers=headers, json=payload)
if (r.status_code == requests.codes.ok):
print(r.json())
else:
print("Error getting item usages: status code", r.status_code)
r = requests.post(f"{url}/api/v1/auditevents", headers=headers, json=payload)
if (r.status_code == requests.codes.ok):
print(r.json())
else:
print("Error getting audit events: status code", r.status_code)
# For more information on the response, check out our support page
# https://support.1password.com/cs/events-api-reference/