0

Create event summaries

by
Published Dec 20, 2024

Create event summaries for a user. Event summaries are used to track the number of times an event has occurred, the first time it occurred and the last time it occurred.

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
 * Create event summaries
8
 * Create event summaries for a user. Event summaries are used to track the number of times an event has occurred, the first time it occurred and the last time it occurred.
9

10

11
 */
12
export async function main(
13
	auth: Intercom,
14
	body: {
15
		user_id?: string
16
		event_summaries?: {
17
			event_name?: string
18
			count?: number
19
			first?: number
20
			last?: number
21
		}
22
	}
23
) {
24
	const url = new URL(`https://api.intercom.io/events/summaries`)
25

26
	const response = await fetch(url, {
27
		method: 'POST',
28
		headers: {
29
			'Intercom-Version': auth.apiVersion,
30
			'Content-Type': 'application/json',
31
			Authorization: 'Bearer ' + auth.token
32
		},
33
		body: JSON.stringify(body)
34
	})
35
	if (!response.ok) {
36
		const text = await response.text()
37
		throw new Error(`${response.status} ${text}`)
38
	}
39
	return await response.text()
40
}
41