0

List users

by
Published Oct 17, 2025
Script salesflare Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Salesflare = {
3
  apiKey: string;
4
};
5
/**
6
 * List users
7
 *
8
 */
9
export async function main(
10
  auth: Salesflare,
11
  id: string | undefined,
12
  name: string | undefined,
13
  email: string | undefined,
14
  search: string | undefined,
15
  limit: string | undefined,
16
  offset: string | undefined,
17
  order_by: string | undefined,
18
  onlyEnabled: string | undefined,
19
) {
20
  const url = new URL(`https://api.salesflare.com/users`);
21
  for (const [k, v] of [
22
    ["id", id],
23
    ["name", name],
24
    ["email", email],
25
    ["search", search],
26
    ["limit", limit],
27
    ["offset", offset],
28
    ["order_by", order_by],
29
    ["onlyEnabled", onlyEnabled],
30
  ]) {
31
    if (v !== undefined && v !== "" && k !== undefined) {
32
      url.searchParams.append(k, v);
33
    }
34
  }
35
  const response = await fetch(url, {
36
    method: "GET",
37
    headers: {
38
      Authorization: "Bearer " + auth.apiKey,
39
    },
40
    body: undefined,
41
  });
42
  if (!response.ok) {
43
    const text = await response.text();
44
    throw new Error(`${response.status} ${text}`);
45
  }
46
  return await response.text();
47
}
48