0

Get customer

by
Published Apr 8, 2025

Retrieve a single customer by its ID. > 🔑 Access with > > API key

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 customer
7
 * Retrieve a single customer by its ID.
8

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