0

List all data events

by
Published Dec 20, 2024

> 🚧 > > Please note that you can only 'list' events that are less than 90 days old.

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 data events
8
 * 
9
> 🚧
10
>
11
> Please note that you can only 'list' events that are less than 90 days old.
12
 */
13
export async function main(
14
	auth: Intercom,
15
	filter: string | undefined,
16
	type: string | undefined,
17
	summary: string | undefined
18
) {
19
	const url = new URL(`https://api.intercom.io/events`)
20
	for (const [k, v] of [
21
		['filter', filter],
22
		['type', type],
23
		['summary', summary]
24
	]) {
25
		if (v !== undefined && v !== '' && k !== undefined) {
26
			url.searchParams.append(k, v)
27
		}
28
	}
29
	const response = await fetch(url, {
30
		method: 'GET',
31
		headers: {
32
			'Intercom-Version': auth.apiVersion,
33
			Authorization: 'Bearer ' + auth.token
34
		},
35
		body: undefined
36
	})
37
	if (!response.ok) {
38
		const text = await response.text()
39
		throw new Error(`${response.status} ${text}`)
40
	}
41
	return await response.json()
42
}
43