0

Get balance report

by
Published Apr 8, 2025

Retrieve a summarized report for all transactions on a given balance within a given timeframe. The API also provides a detailed report on all 'prepayments' for Mollie fees that were deducted from your balance during the reported period, ahead of your Mollie invoice. The alias `primary` can be used instead of the balance ID to refer to the organization's primary balance. > 🔑 Access with > > Access token with **balance-reports.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
 * Get balance report
7
 * Retrieve a summarized report for all transactions on a given balance within a given timeframe.
8

9
The API also provides a detailed report on all 'prepayments' for Mollie fees that were deducted from your balance during the reported period, ahead of your Mollie invoice.
10

11
The alias `primary` can be used instead of the balance ID to refer to the organization's primary balance.
12

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