0

Demote a branch

by
Published Oct 17, 2025

Demotes a branch from production to development ### Authorization A OAuth token must have at least one of the following scopes in order to use this API endpoint: **OAuth Scopes** | Resource | Scopes | | :------- | :---------- | | Organization | `demote_branches` | | Database | `demote_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
 * Demote a branch
8
 * Demotes a branch from production to development
9
### Authorization
10
A   OAuth token must have at least one of the following   scopes in order to use this API endpoint:
11

12
**OAuth Scopes**
13

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

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