0

List tasks

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 tasks
7
 *
8
 */
9
export async function main(
10
  auth: Salesflare,
11
  id: string | undefined,
12
  search: string | undefined,
13
  assignees: string | undefined,
14
  _type: string | undefined,
15
  account: string | undefined,
16
  order_by: string | undefined,
17
  limit: string | undefined,
18
  offset: string | undefined,
19
  _export: string | undefined,
20
  q: string | undefined,
21
) {
22
  const url = new URL(`https://api.salesflare.com/tasks`);
23
  for (const [k, v] of [
24
    ["id", id],
25
    ["search", search],
26
    ["assignees", assignees],
27
    ["type", _type],
28
    ["account", account],
29
    ["order_by", order_by],
30
    ["limit", limit],
31
    ["offset", offset],
32
    ["export", _export],
33
    ["q", q],
34
  ]) {
35
    if (v !== undefined && v !== "" && k !== undefined) {
36
      url.searchParams.append(k, v);
37
    }
38
  }
39
  const response = await fetch(url, {
40
    method: "GET",
41
    headers: {
42
      Authorization: "Bearer " + auth.apiKey,
43
    },
44
    body: undefined,
45
  });
46
  if (!response.ok) {
47
    const text = await response.text();
48
    throw new Error(`${response.status} ${text}`);
49
  }
50
  return await response.text();
51
}
52