0

AddGroupToCustomer

by
Published Oct 17, 2025

Adds a group membership to a customer. The customer is identified by the `customer_id` value and the customer group is identified by the `group_id` value.

Script square Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Square = {
3
  token: string;
4
};
5
/**
6
 * AddGroupToCustomer
7
 * Adds a group membership to a customer.
8

9
The customer is identified by the `customer_id` value
10
and the customer group is identified by the `group_id` value.
11
 */
12
export async function main(
13
  auth: Square,
14
  customer_id: string,
15
  group_id: string,
16
) {
17
  const url = new URL(
18
    `https://connect.squareup.com/v2/customers/${customer_id}/groups/${group_id}`,
19
  );
20

21
  const response = await fetch(url, {
22
    method: "PUT",
23
    headers: {
24
      Authorization: "Bearer " + auth.token,
25
    },
26
    body: undefined,
27
  });
28
  if (!response.ok) {
29
    const text = await response.text();
30
    throw new Error(`${response.status} ${text}`);
31
  }
32
  return await response.json();
33
}
34