0

Get current user

by
Published Oct 17, 2025

Get the user associated with this service token ### Authorization A OAuth token must have at least one of the following scopes in order to use this API endpoint: **OAuth Scopes** | Resource | Scopes | | :------- | :---------- | | User | `read_user` |

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 current user
8
 * Get the user associated with this service token
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
| User | `read_user` |
17
 */
18
export async function main(auth: Planetscale) {
19
  const url = new URL(`https://api.planetscale.com/v1/user`);
20

21
  const response = await fetch(url, {
22
    method: "GET",
23
    headers: {
24
      Authorization: `${auth.serviceTokenId}:${auth.serviceToken}`,
25
    },
26
    body: undefined,
27
  });
28
  if (!response.ok) {
29
    const text = await response.text();
30
    throw new Error(`${response.status} ${text}`);
31
  }
32
  return await response.json();
33
}
34