Get Groups
One script reply has been approved by the moderators Verified

This endpoint is used to view User Groups in your Workspace.

In our API documentation, team_id refers to the ID of a Workspace, and group_id refers to the ID of a User Group.

Created by hugo697 168 days ago Picked 1 time
Submitted by hugo697 Bun
Verified 168 days ago
1
//native
2
type Clickup = {
3
  token: string;
4
};
5
/**
6
 * Get Groups
7
 * This endpoint is used to view [User Groups](https://docs.clickup.com/en/articles/4010016-teams-how-to-create-user-groups) in your Workspace.\
8
 \
9
In our API documentation, `team_id` refers to the ID of a Workspace, and `group_id` refers to the ID of a User Group.
10
 */
11
export async function main(
12
  auth: Clickup,
13
  team_id: string | undefined,
14
  group_ids: string | undefined,
15
) {
16
  const url = new URL(`https://api.clickup.com/api/v2/group`);
17
  for (const [k, v] of [
18
    ["team_id", team_id],
19
    ["group_ids", group_ids],
20
  ]) {
21
    if (v !== undefined && v !== "" && k !== undefined) {
22
      url.searchParams.append(k, v);
23
    }
24
  }
25
  const response = await fetch(url, {
26
    method: "GET",
27
    headers: {
28
      Authorization: auth.token,
29
    },
30
    body: undefined,
31
  });
32
  if (!response.ok) {
33
    const text = await response.text();
34
    throw new Error(`${response.status} ${text}`);
35
  }
36
  return await response.json();
37
}
38