0

List balances

by
Published Apr 8, 2025

Retrieve a list of the organization's balances, including the primary balance. The results are paginated. > 🔑 Access with > > Access token with **balances.read**

Script mollie Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Mollie = {
3
  token: string;
4
};
5
/**
6
 * List balances
7
 * Retrieve a list of the organization's balances, including the primary balance.
8

9
The results are paginated.
10

11
> 🔑 Access with
12
>
13
> Access token with **balances.read**
14
 */
15
export async function main(
16
  auth: Mollie,
17
  currency: string | undefined,
18
  from: string | undefined,
19
  limit: string | undefined,
20
  testmode: string | undefined,
21
) {
22
  const url = new URL(`https://api.mollie.com/v2/balances`);
23
  for (const [k, v] of [
24
    ["currency", currency],
25
    ["from", from],
26
    ["limit", limit],
27
    ["testmode", testmode],
28
  ]) {
29
    if (v !== undefined && v !== "" && k !== undefined) {
30
      url.searchParams.append(k, v);
31
    }
32
  }
33
  const response = await fetch(url, {
34
    method: "GET",
35
    headers: {
36
      Authorization: "Bearer " + auth.token,
37
    },
38
    body: undefined,
39
  });
40
  if (!response.ok) {
41
    const text = await response.text();
42
    throw new Error(`${response.status} ${text}`);
43
  }
44
  return await response.text();
45
}
46