0

List regions for an organization

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_organization` **OAuth Scopes** | Resource | Scopes | | :------- | :---------- | | User | `read_organizations` | | Organization | `read_organization` |

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 regions for an organization
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_organization`
14

15
**OAuth Scopes**
16

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