0

List all activity logs

by
Published Dec 20, 2024

You can get a log of activities by all admins in an app.

Script intercom Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Intercom = {
3
	apiVersion: string
4
	token: string
5
}
6
/**
7
 * List all activity logs
8
 * You can get a log of activities by all admins in an app.
9
 */
10
export async function main(
11
	auth: Intercom,
12
	created_at_after: string | undefined,
13
	created_at_before: string | undefined
14
) {
15
	const url = new URL(`https://api.intercom.io/admins/activity_logs`)
16
	for (const [k, v] of [
17
		['created_at_after', created_at_after],
18
		['created_at_before', created_at_before]
19
	]) {
20
		if (v !== undefined && v !== '' && k !== undefined) {
21
			url.searchParams.append(k, v)
22
		}
23
	}
24
	const response = await fetch(url, {
25
		method: 'GET',
26
		headers: {
27
			'Intercom-Version': auth.apiVersion,
28
			Authorization: 'Bearer ' + auth.token
29
		},
30
		body: undefined
31
	})
32
	if (!response.ok) {
33
		const text = await response.text()
34
		throw new Error(`${response.status} ${text}`)
35
	}
36
	return await response.json()
37
}
38