0

List deploy requests

by
Published Oct 17, 2025

List deploy requests for a database ### 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** `read_deploy_request` **OAuth Scopes** | Resource | Scopes | | :------- | :---------- | | Organization | `read_deploy_requests` | | Database | `read_deploy_requests` |

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
 * List deploy requests
8
 * List deploy requests for a database
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
 `read_deploy_request`
14

15
**OAuth Scopes**
16

17
 | Resource | Scopes |
18
| :------- | :---------- |
19
| Organization | `read_deploy_requests` |
20
| Database | `read_deploy_requests` |
21
 */
22
export async function main(
23
  auth: Planetscale,
24
  organization: string,
25
  database: string,
26
  page: string | undefined,
27
  per_page: string | undefined,
28
  state: string | undefined,
29
  branch: string | undefined,
30
  into_branch: string | undefined,
31
) {
32
  const url = new URL(
33
    `https://api.planetscale.com/v1/organizations/${organization}/databases/${database}/deploy-requests`,
34
  );
35
  for (const [k, v] of [
36
    ["page", page],
37
    ["per_page", per_page],
38
    ["state", state],
39
    ["branch", branch],
40
    ["into_branch", into_branch],
41
  ]) {
42
    if (v !== undefined && v !== "" && k !== undefined) {
43
      url.searchParams.append(k, v);
44
    }
45
  }
46
  const response = await fetch(url, {
47
    method: "GET",
48
    headers: {
49
      Authorization: `${auth.serviceTokenId}:${auth.serviceToken}`,
50
    },
51
    body: undefined,
52
  });
53
  if (!response.ok) {
54
    const text = await response.text();
55
    throw new Error(`${response.status} ${text}`);
56
  }
57
  return await response.json();
58
}
59