0

Add Group Members

by
Published Oct 17, 2025

Adds one or more members to a group.

Script smartsheet Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Smartsheet = {
3
  token: string;
4
  baseUrl: string;
5
};
6
/**
7
 * Add Group Members
8
 * Adds one or more members to a group.
9
 */
10
export async function main(
11
  auth: Smartsheet,
12
  groupId: string,
13
  body:
14
    | {
15
        id?: number;
16
        email?: string;
17
        firstName?: string;
18
        lastName?: string;
19
        name?: string;
20
      }
21
    | {
22
        id?: number;
23
        email?: string;
24
        firstName?: string;
25
        lastName?: string;
26
        name?: string;
27
      }[],
28
) {
29
  const url = new URL(`${auth.baseUrl}/groups/${groupId}/members`);
30

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