0

Get instance count

by
Published Oct 17, 2025

Get the instance count for one or more resources.

Script render Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Render = {
3
	apiKey: string
4
}
5
/**
6
 * Get instance count
7
 * Get the instance count for one or more resources.
8

9
 */
10
export async function main(
11
	auth: Render,
12
	startTime: string | undefined,
13
	endTime: string | undefined,
14
	resolutionSeconds: string | undefined,
15
	resource: string | undefined,
16
	service: string | undefined
17
) {
18
	const url = new URL(`https://api.render.com/v1/metrics/instance-count`)
19
	for (const [k, v] of [
20
		['startTime', startTime],
21
		['endTime', endTime],
22
		['resolutionSeconds', resolutionSeconds],
23
		['resource', resource],
24
		['service', service]
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