-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patheventsapi.js
More file actions
53 lines (44 loc) · 1.46 KB
/
eventsapi.js
File metadata and controls
53 lines (44 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
43
44
45
46
47
48
49
50
51
52
53
// For more information, check out our support page
// https://support.1password.com/events-reporting
const apiToken = process.env.EVENTS_API_TOKEN;
const url = "https://events.1password.com";
const startTime = new Date();
startTime.setHours(startTime.getHours() - 24);
const headers = {
"Content-Type": "application/json",
Authorization: `Bearer ${apiToken}`,
};
const payload = {
limit: 20,
start_time: startTime.toISOString().replace(/\.\d{3}Z$/, "Z"),
};
// Alternatively, use the cursor returned from previous responses to get any new events
// payload = { "cursor": cursor }
const options = {
method: "POST",
body: JSON.stringify(payload),
headers,
};
fetch(`${url}/api/v1/signinattempts`, options).then(async (response) => {
if (response.ok) {
console.log(await response.json());
} else {
console.log("Error getting sign in attempts: status code", response.status);
}
});
fetch(`${url}/api/v1/itemusages`, options).then(async (response) => {
if (response.ok) {
console.log(await response.json());
} else {
console.log("Error getting item usages: status code", response.status);
}
});
fetch(`${url}/api/v1/auditevents`, options).then(async (response) => {
if (response.ok) {
console.log(await response.json());
} else {
console.log("Error getting audit events: status code", response.status);
}
});
// For more information on the response, check out our support page
// https://support.1password.com/cs/events-api-reference/