0

Update autoscaling config

by
Published Oct 17, 2025

Update the [autoscaling](https://docs.render.com/scaling#autoscaling) config 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
 * Update autoscaling config
7
 * Update the [autoscaling](https://docs.render.com/scaling#autoscaling) config for the service with the provided ID.
8

9
 */
10
export async function main(
11
	auth: Render,
12
	serviceId: string,
13
	body: {
14
		enabled: false | true
15
		min: number
16
		max: number
17
		criteria: {
18
			cpu: { enabled: false | true; percentage: number }
19
			memory: { enabled: false | true; percentage: number }
20
		}
21
	}
22
) {
23
	const url = new URL(`https://api.render.com/v1/services/${serviceId}/autoscaling`)
24

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