Edits history of script submission #23009 for ' List Users (linear)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * List Users
     * List workspace members. With search, only users whose name, display name or email contains it (case-insensitive) are returned. Paginate with after = pageInfo.endCursor.
     */
    export async function main(
      auth: RT.Linear,
      search: string | undefined,
      include_disabled: boolean = false,
      first: number = 50,
      after: string | undefined
    ) {
      const filter = search
        ? {
            or: [
              { name: { containsIgnoreCase: search } },
              { displayName: { containsIgnoreCase: search } },
              { email: { containsIgnoreCase: search } },
            ],
          }
        : 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: 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 } } }`,
          variables: {
            filter,
            includeDisabled: include_disabled,
            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.users
    }
    

    Submitted by hugo989 1 hour ago