0

Get a database

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_database`, `delete_database`, `write_database`, `read_branch`, `delete_branch`, `create_branch`, `delete_production_branch`, `connect_branch`, `connect_production_branch`, `delete_branch_password`, `delete_production_branch_password`, `read_deploy_request`, `create_deploy_request`, `approve_deploy_request`, `read_schema_recommendations`, `close_schema_recommendations`, `read_comment`, `create_comment`, `restore_backup`, `restore_production_branch_backup`, `read_backups`, `write_backups`, `delete_backups`, `delete_production_branch_backups` **OAuth Scopes** | Resource | Scopes | | :------- | :---------- | | Organization | `read_databases` | | Database | `read_database` |.

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
 * Get a database
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_database`, `delete_database`, `write_database`, `read_branch`, `delete_branch`, `create_branch`, `delete_production_branch`, `connect_branch`, `connect_production_branch`, `delete_branch_password`, `delete_production_branch_password`, `read_deploy_request`, `create_deploy_request`, `approve_deploy_request`, `read_schema_recommendations`, `close_schema_recommendations`, `read_comment`, `create_comment`, `restore_backup`, `restore_production_branch_backup`, `read_backups`, `write_backups`, `delete_backups`, `delete_production_branch_backups`
14

15
**OAuth Scopes**
16

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

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