0

Lint a branch schema

by
Published Oct 17, 2025

### 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_branch`, `delete_branch`, `create_branch`, `connect_production_branch`, `connect_branch` **OAuth Scopes** | Resource | Scopes | | :------- | :---------- | | Organization | `read_branches` | | Database | `read_branches` | | Branch | `read_branch` |

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
 * Lint a branch schema
8
 * 
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_branch`, `delete_branch`, `create_branch`, `connect_production_branch`, `connect_branch`
14

15
**OAuth Scopes**
16

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