0

List Views

by
Published today

List saved custom views.

Script linear Verified

The script

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

3
/**
4
 * List Views
5
 * List saved custom views, optionally only those of one team. Use a view's id with Get View Issues. 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: CustomViewFilter, $first: Int, $after: String) { customViews(filter: $filter, first: $first, after: $after, orderBy: updatedAt) { nodes { id name description modelName shared slugId createdAt updatedAt team { id key } owner { id name } } 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.customViews
40
}
41