0

List tags

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