0

CreateCustomerGroup

by
Published Oct 17, 2025

Creates a new customer group for a business. The request must include the `name` value of the group.

Script square Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Square = {
3
  token: string;
4
};
5
/**
6
 * CreateCustomerGroup
7
 * Creates a new customer group for a business.
8

9
The request must include the `name` value of the group.
10
 */
11
export async function main(
12
  auth: Square,
13
  body: {
14
    idempotency_key?: string;
15
    group: {
16
      id?: string;
17
      name: string;
18
      created_at?: string;
19
      updated_at?: string;
20
    };
21
  },
22
) {
23
  const url = new URL(`https://connect.squareup.com/v2/customers/groups`);
24

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