0

Set branch as default

by
Published Apr 8, 2025

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

13
 */
14
export async function main(auth: Neondb, project_id: string, branch_id: string) {
15
	const url = new URL(
16
		`https://console.neon.tech/api/v2/projects/${project_id}/branches/${branch_id}/set_as_default`
17
	)
18

19
	const response = await fetch(url, {
20
		method: 'POST',
21
		headers: {
22
			Authorization: 'Bearer ' + auth.apiKey
23
		},
24
		body: undefined
25
	})
26
	if (!response.ok) {
27
		const text = await response.text()
28
		throw new Error(`${response.status} ${text}`)
29
	}
30
	return await response.json()
31
}
32