0

List mandates

by
Published Apr 8, 2025

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

9
The results are paginated.
10

11
> 🔑 Access with
12
>
13
> API key
14
>
15
> Access token with **mandates.read**
16
 */
17
export async function main(
18
  auth: Mollie,
19
  customerId: string,
20
  from: string | undefined,
21
  limit: string | undefined,
22
  testmode: string | undefined,
23
) {
24
  const url = new URL(
25
    `https://api.mollie.com/v2/customers/${customerId}/mandates`,
26
  );
27
  for (const [k, v] of [
28
    ["from", from],
29
    ["limit", limit],
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