0

Update a project

by
Published Apr 8, 2025

Updates the specified project. You can obtain a `project_id` by listing the projects for your Neon account. Neon permits updating the project name only.

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 project
7
 * Updates the specified project.
8
You can obtain a `project_id` by listing the projects for your Neon account.
9
Neon permits updating the project name only.
10

11
 */
12
export async function main(
13
	auth: Neondb,
14
	project_id: string,
15
	body: {
16
		project: {
17
			settings?: {
18
				quota?: {
19
					active_time_seconds?: number
20
					compute_time_seconds?: number
21
					written_data_bytes?: number
22
					data_transfer_bytes?: number
23
					logical_size_bytes?: number
24
				}
25
				allowed_ips?: {
26
					ips?: string[]
27
					protected_branches_only?: false | true
28
				}
29
				enable_logical_replication?: false | true
30
				maintenance_window?: {
31
					weekdays: number[]
32
					start_time: string
33
					end_time: string
34
				}
35
				block_public_connections?: false | true
36
				block_vpc_connections?: false | true
37
			}
38
			name?: string
39
			default_endpoint_settings?: {
40
				pg_settings?: {}
41
				pgbouncer_settings?: {}
42
				autoscaling_limit_min_cu?: number
43
				autoscaling_limit_max_cu?: number
44
				suspend_timeout_seconds?: number
45
			}
46
			history_retention_seconds?: number
47
		}
48
	}
49
) {
50
	const url = new URL(`https://console.neon.tech/api/v2/projects/${project_id}`)
51

52
	const response = await fetch(url, {
53
		method: 'PATCH',
54
		headers: {
55
			'Content-Type': 'application/json',
56
			Authorization: 'Bearer ' + auth.apiKey
57
		},
58
		body: JSON.stringify(body)
59
	})
60
	if (!response.ok) {
61
		const text = await response.text()
62
		throw new Error(`${response.status} ${text}`)
63
	}
64
	return await response.json()
65
}
66