Edits history of script submission #23261 for ' List Views (linear)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * List Views
     * List saved custom views, optionally only those of one team. Use a view's id with Get View Issues. Paginate with after = pageInfo.endCursor.
     */
    export async function main(
      auth: RT.Linear,
      team_id: string | undefined,
      first: number = 50,
      after: string | undefined
    ) {
      const response = await fetch("https://api.linear.app/graphql", {
        method: "POST",
        headers: {
          Authorization: auth.apiKey,
          "Content-Type": "application/json",
          Accept: "application/json",
        },
        body: JSON.stringify({
          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 } } }`,
          variables: {
            filter: team_id ? { team: { id: { eq: team_id } } } : undefined,
            first,
            after: after || undefined,
          },
        }),
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      const { data, errors } = await response.json()
      if (errors) {
        throw new Error(JSON.stringify(errors))
      }
    
      return data.customViews
    }
    

    Submitted by hugo989 2 hours ago