Edits history of script submission #12640 for ' Update customer (mollie)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Mollie = {
      token: string;
    };
    /**
     * Update customer
     * Update an existing customer.
    
    For an in-depth explanation of each parameter, refer to the [Create customer](create-customer) endpoint.
    
    > 🔑 Access with
    >
    > API key
     */
    export async function main(
      auth: Mollie,
      id: string,
      body: { name?: string; email?: string; locale?: string; metadata?: string },
    ) {
      const url = new URL(`https://api.mollie.com/v2/customers/${id}`);
    
      const response = await fetch(url, {
        method: "PATCH",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 428 days ago