0

List clients

by
Published Apr 8, 2025

Retrieve a list of all clients linked to your account. The results are paginated. > 🔑 Access with > > Access token with **clients.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 clients
7
 * Retrieve a list of all clients linked to your account.
8

9
The results are paginated.
10

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