0

Get invoices

by
Published Oct 17, 2025

Get the invoices for an organization ### 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_invoices` **OAuth Scopes** | Resource | Scopes | | :------- | :---------- | | Organization | `read_invoices` |

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 invoices
8
 * Get the invoices for an organization
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_invoices`
14

15
**OAuth Scopes**
16

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