0

List Cycles

by
Published today

List cycles (sprints), optionally for one team.

Script linear Verified

The script

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

3
/**
4
 * List Cycles
5
 * List cycles (sprints), optionally for one team. Paginate with after = pageInfo.endCursor.
6
 */
7
export async function main(
8
  auth: RT.Linear,
9
  team_id: string | undefined,
10
  first: number = 50,
11
  after: string | undefined
12
) {
13
  const response = await fetch("https://api.linear.app/graphql", {
14
    method: "POST",
15
    headers: {
16
      Authorization: auth.apiKey,
17
      "Content-Type": "application/json",
18
      Accept: "application/json",
19
    },
20
    body: JSON.stringify({
21
      query: `query ($filter: CycleFilter, $first: Int, $after: String) { cycles(filter: $filter, first: $first, after: $after) { nodes { id number name startsAt endsAt completedAt progress isActive team { id key } } pageInfo { hasNextPage endCursor } } }`,
22
      variables: {
23
        filter: team_id ? { team: { id: { eq: team_id } } } : undefined,
24
        first,
25
        after: after || undefined,
26
      },
27
    }),
28
  })
29

30
  if (!response.ok) {
31
    throw new Error(`${response.status} ${await response.text()}`)
32
  }
33

34
  const { data, errors } = await response.json()
35
  if (errors) {
36
    throw new Error(JSON.stringify(errors))
37
  }
38

39
  return data.cycles
40
}
41