0

Add Users to User Group

by
Published Oct 17, 2025

Adds a list of users or invites to a user group. • When called, this endpoint may generate one or more of the following audit trail events:* Subjects Added to Group * User Added To User Group The rate limit for this endpoint is 60 requests per minute, which is lower than the default due to access pattern restrictions. Once reached, this endpoint will respond with the 429 HTTP status code with headers indicating the limit parameters. See Rate Limiting for more information.

Script segment Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Segment = {
3
  token: string;
4
  baseUrl: string;
5
};
6
/**
7
 * Add Users to User Group
8
 * Adds a list of users or invites to a user group.
9

10

11

12
• When called, this endpoint may generate one or more of the following audit trail events:* Subjects Added to Group
13
* User Added To User Group
14
      
15

16

17
The rate limit for this endpoint is 60 requests per minute, which is lower than the default due to access pattern restrictions. Once reached, this endpoint will respond with the 429 HTTP status code with headers indicating the limit parameters. See Rate Limiting for more information.
18
 */
19
export async function main(
20
  auth: Segment,
21
  userGroupId: string,
22
  body: { emails: string[] },
23
) {
24
  const url = new URL(
25
    `${auth.baseUrl}/groups/${userGroupId}/users`,
26
  );
27

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