0

List Teams

by
Published today

List the teams in the Linear workspace. Most other actions need a team ID from here.

Script linear Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 1 hour ago
1
//native
2

3
/**
4
 * List Teams
5
 * List the teams in the Linear workspace, with their ID, key and name. Paginate with after = pageInfo.endCursor.
6
 */
7
export async function main(
8
  auth: RT.Linear,
9
  first: number = 50,
10
  after: string | undefined
11
) {
12
  const response = await fetch("https://api.linear.app/graphql", {
13
    method: "POST",
14
    headers: {
15
      Authorization: auth.apiKey,
16
      "Content-Type": "application/json",
17
      Accept: "application/json",
18
    },
19
    body: JSON.stringify({
20
      query: `query ($first: Int, $after: String) { teams(first: $first, after: $after) { nodes { id key name description private } pageInfo { hasNextPage endCursor } } }`,
21
      variables: { first, after: after || undefined },
22
    }),
23
  })
24

25
  if (!response.ok) {
26
    throw new Error(`${response.status} ${await response.text()}`)
27
  }
28

29
  const { data, errors } = await response.json()
30
  if (errors) {
31
    throw new Error(JSON.stringify(errors))
32
  }
33

34
  return data.teams
35
}
36