0

List all refunds

by
Published Apr 8, 2025

Retrieve a list of all of your refunds. The results are paginated. > 🔑 Access with > > API key > > Access token with **refunds.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 all refunds
7
 * Retrieve a list of all of your refunds.
8

9
The results are paginated.
10

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