0

Update a compute endpoint

by
Published Apr 8, 2025

Updates the specified compute endpoint.

Script neondb Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Neondb = {
3
	apiKey: string
4
}
5
/**
6
 * Update a compute endpoint
7
 * Updates the specified compute endpoint.
8
 */
9
export async function main(
10
	auth: Neondb,
11
	project_id: string,
12
	endpoint_id: string,
13
	body: {
14
		endpoint: {
15
			branch_id?: string
16
			autoscaling_limit_min_cu?: number
17
			autoscaling_limit_max_cu?: number
18
			provisioner?: string
19
			settings?: { pg_settings?: {}; pgbouncer_settings?: {} }
20
			pooler_enabled?: false | true
21
			pooler_mode?: 'transaction'
22
			disabled?: false | true
23
			passwordless_access?: false | true
24
			suspend_timeout_seconds?: number
25
		}
26
	}
27
) {
28
	const url = new URL(
29
		`https://console.neon.tech/api/v2/projects/${project_id}/endpoints/${endpoint_id}`
30
	)
31

32
	const response = await fetch(url, {
33
		method: 'PATCH',
34
		headers: {
35
			'Content-Type': 'application/json',
36
			Authorization: 'Bearer ' + auth.apiKey
37
		},
38
		body: JSON.stringify(body)
39
	})
40
	if (!response.ok) {
41
		const text = await response.text()
42
		throw new Error(`${response.status} ${text}`)
43
	}
44
	return await response.json()
45
}
46