0

Fetch cluster logs

by
Published Oct 17, 2025

Fetch cluster logs

Script qovery Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Fetch cluster logs
4
 * Fetch cluster logs
5
 */
6
export async function main(
7
	auth: RT.Qovery,
8
	clusterId: string,
9
	endpoint: string | undefined,
10
	query: string | undefined,
11
	start?: string | undefined,
12
	end?: string | undefined,
13
	limit?: string | undefined,
14
	since?: string | undefined,
15
	step?: string | undefined,
16
	interval?: string | undefined,
17
	direction?: string | undefined
18
) {
19
	const url = new URL(`https://api.qovery.com/cluster/${clusterId}/logs`)
20
	for (const [k, v] of [
21
		['endpoint', endpoint],
22
		['query', query],
23
		['start', start],
24
		['end', end],
25
		['limit', limit],
26
		['since', since],
27
		['step', step],
28
		['interval', interval],
29
		['direction', direction]
30
	]) {
31
		if (v !== undefined && v !== '') {
32
			url.searchParams.append(k, v)
33
		}
34
	}
35
	const response = await fetch(url, {
36
		method: 'GET',
37
		headers: {
38
			Authorization: 'Token ' + auth.apiKey
39
		},
40
		body: undefined
41
	})
42
	if (!response.ok) {
43
		const text = await response.text()
44
		throw new Error(`${response.status} ${text}`)
45
	}
46
	return await response.json()
47
}
48