0

Update a branch

by
Published Apr 8, 2025

Updates the specified branch. You can obtain a `project_id` by listing the projects for your Neon account. You can obtain the `branch_id` by listing the project's branches. For more information, see [Manage branches](https://neon.tech/docs/manage/branches/).

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 branch
7
 * Updates the specified branch.
8
You can obtain a `project_id` by listing the projects for your Neon account.
9
You can obtain the `branch_id` by listing the project's branches.
10
For more information, see [Manage branches](https://neon.tech/docs/manage/branches/).
11

12
 */
13
export async function main(
14
	auth: Neondb,
15
	project_id: string,
16
	branch_id: string,
17
	body: { branch: { name?: string; protected?: false | true } }
18
) {
19
	const url = new URL(
20
		`https://console.neon.tech/api/v2/projects/${project_id}/branches/${branch_id}`
21
	)
22

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