0

List Workflow States

by
Published today

List workflow states (issue statuses), 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 Workflow States
5
 * List workflow states (issue statuses such as Todo, In Progress, Done). States are per team — pass team_id to get the IDs valid for that team's issues.
6
 */
7
export async function main(
8
  auth: RT.Linear,
9
  team_id: string | undefined,
10
  first: number = 100,
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: WorkflowStateFilter, $first: Int, $after: String) { workflowStates(filter: $filter, first: $first, after: $after) { nodes { id name type color position 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.workflowStates
40
}
41