0

Update customer

by
Published Apr 8, 2025

Update an existing customer. For an in-depth explanation of each parameter, refer to the [Create customer](create-customer) endpoint. > 🔑 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
 * Update customer
7
 * Update an existing customer.
8

9
For an in-depth explanation of each parameter, refer to the [Create customer](create-customer) endpoint.
10

11
> 🔑 Access with
12
>
13
> API key
14
 */
15
export async function main(
16
  auth: Mollie,
17
  id: string,
18
  body: { name?: string; email?: string; locale?: string; metadata?: string },
19
) {
20
  const url = new URL(`https://api.mollie.com/v2/customers/${id}`);
21

22
  const response = await fetch(url, {
23
    method: "PATCH",
24
    headers: {
25
      "Content-Type": "application/json",
26
      Authorization: "Bearer " + auth.token,
27
    },
28
    body: JSON.stringify(body),
29
  });
30
  if (!response.ok) {
31
    const text = await response.text();
32
    throw new Error(`${response.status} ${text}`);
33
  }
34
  return await response.text();
35
}
36