0

List customers

by
Published Apr 8, 2025

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

9
The results are paginated.
10

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