0

List filter fields for an entity

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