0

Create customer

by
Published Apr 8, 2025

Creates a simple minimal representation of a customer. Payments, recurring mandates, and subscriptions can be linked to this customer object, which simplifies management of recurring payments. Once registered, customers will also appear in your Mollie dashboard. > 🔑 Access with > > API key > > Access token with **customers.write**

Script mollie Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Mollie = {
3
  token: string;
4
};
5
/**
6
 * Create customer
7
 * Creates a simple minimal representation of a customer. Payments, recurring mandates, and subscriptions can be linked to this customer object, which simplifies management of recurring payments.
8

9
Once registered, customers will also appear in your Mollie dashboard.
10

11
> 🔑 Access with
12
>
13
> API key
14
>
15
> Access token with **customers.write**
16
 */
17
export async function main(
18
  auth: Mollie,
19
  body: {
20
    resource?: string;
21
    id?: string;
22
    mode?: string;
23
    name?: string;
24
    email?: string;
25
    locale?: string;
26
    metadata?: string | {} | string[];
27
    createdAt?: string;
28
    testmode?: false | true;
29
    _links?: {
30
      self?: { href?: string; type?: string };
31
      payments?: { href?: string; type?: string };
32
      mandates?: { href?: string; type?: string };
33
      subscriptions?: { href?: string; type?: string };
34
      documentation?: { href?: string; type?: string };
35
    };
36
  },
37
) {
38
  const url = new URL(`https://api.mollie.com/v2/customers`);
39

40
  const response = await fetch(url, {
41
    method: "POST",
42
    headers: {
43
      "Content-Type": "application/json",
44
      Authorization: "Bearer " + auth.token,
45
    },
46
    body: JSON.stringify(body),
47
  });
48
  if (!response.ok) {
49
    const text = await response.text();
50
    throw new Error(`${response.status} ${text}`);
51
  }
52
  return await response.text();
53
}
54