0

List events

by
Published Oct 17, 2025

List recent events that occurred for the service with the provided ID.

Script render Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Render = {
3
	apiKey: string
4
}
5
/**
6
 * List events
7
 * List recent events that occurred for the service with the provided ID.
8
 */
9
export async function main(
10
	auth: Render,
11
	serviceId: string,
12
	_type: string | undefined,
13
	startTime: string | undefined,
14
	endTime: string | undefined,
15
	cursor: string | undefined,
16
	limit: string | undefined
17
) {
18
	const url = new URL(`https://api.render.com/v1/services/${serviceId}/events`)
19
	for (const [k, v] of [
20
		['type', _type],
21
		['startTime', startTime],
22
		['endTime', endTime],
23
		['cursor', cursor],
24
		['limit', limit]
25
	]) {
26
		if (v !== undefined && v !== '' && k !== undefined) {
27
			url.searchParams.append(k, v)
28
		}
29
	}
30
	const response = await fetch(url, {
31
		method: 'GET',
32
		headers: {
33
			Authorization: 'Bearer ' + auth.apiKey
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