0

Promote a branch

by
Published Oct 17, 2025

Promotes a branch from development to production ### Authorization A service token or OAuth token must have at least one of the following access or scopes in order to use this API endpoint: **Service Token Accesses** `connect_production_branch` **OAuth Scopes** | Resource | Scopes | | :------- | :---------- | | Organization | `promote_branches` | | Database | `promote_branches` |

Script planetscale Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Planetscale = {
3
  serviceTokenId: string;
4
  serviceToken: string;
5
};
6
/**
7
 * Promote a branch
8
 * Promotes a branch from development to production
9
### Authorization
10
A service token or OAuth token must have at least one of the following access or scopes in order to use this API endpoint:
11

12
**Service Token Accesses**
13
 `connect_production_branch`
14

15
**OAuth Scopes**
16

17
 | Resource | Scopes |
18
| :------- | :---------- |
19
| Organization | `promote_branches` |
20
| Database | `promote_branches` |
21
 */
22
export async function main(
23
  auth: Planetscale,
24
  organization: string,
25
  database: string,
26
  name: string,
27
) {
28
  const url = new URL(
29
    `https://api.planetscale.com/v1/organizations/${organization}/databases/${database}/branches/${name}/promote`,
30
  );
31

32
  const response = await fetch(url, {
33
    method: "POST",
34
    headers: {
35
      Authorization: `${auth.serviceTokenId}:${auth.serviceToken}`,
36
    },
37
    body: undefined,
38
  });
39
  if (!response.ok) {
40
    const text = await response.text();
41
    throw new Error(`${response.status} ${text}`);
42
  }
43
  return await response.json();
44
}
45