0

List Users

by
Published today

List workspace members, optionally filtered by name or email.

Script linear Verified

The script

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

3
/**
4
 * List Users
5
 * List workspace members. With search, only users whose name, display name or email contains it (case-insensitive) are returned. Paginate with after = pageInfo.endCursor.
6
 */
7
export async function main(
8
  auth: RT.Linear,
9
  search: string | undefined,
10
  include_disabled: boolean = false,
11
  first: number = 50,
12
  after: string | undefined
13
) {
14
  const filter = search
15
    ? {
16
        or: [
17
          { name: { containsIgnoreCase: search } },
18
          { displayName: { containsIgnoreCase: search } },
19
          { email: { containsIgnoreCase: search } },
20
        ],
21
      }
22
    : undefined
23

24
  const response = await fetch("https://api.linear.app/graphql", {
25
    method: "POST",
26
    headers: {
27
      Authorization: auth.apiKey,
28
      "Content-Type": "application/json",
29
      Accept: "application/json",
30
    },
31
    body: JSON.stringify({
32
      query: `query ($filter: UserFilter, $includeDisabled: Boolean, $first: Int, $after: String) { users(filter: $filter, includeDisabled: $includeDisabled, first: $first, after: $after) { nodes { id name displayName email active admin } pageInfo { hasNextPage endCursor } } }`,
33
      variables: {
34
        filter,
35
        includeDisabled: include_disabled,
36
        first,
37
        after: after || undefined,
38
      },
39
    }),
40
  })
41

42
  if (!response.ok) {
43
    throw new Error(`${response.status} ${await response.text()}`)
44
  }
45

46
  const { data, errors } = await response.json()
47
  if (errors) {
48
    throw new Error(JSON.stringify(errors))
49
  }
50

51
  return data.users
52
}
53