0

List contacts

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 contacts
7
 *
8
 */
9
export async function main(
10
  auth: Salesflare,
11
  id: string | undefined,
12
  name: string | undefined,
13
  email: string | undefined,
14
  phone_number: string | undefined,
15
  domain: string | undefined,
16
  modification_after: string | undefined,
17
  modification_before: string | undefined,
18
  creation_after: string | undefined,
19
  creation_before: string | undefined,
20
  account: string | undefined,
21
  tag: string | undefined,
22
  tag_name: string | undefined,
23
  position_role: string | undefined,
24
  address_country: string | undefined,
25
  address_state_region: string | undefined,
26
  address_city: string | undefined,
27
  includeArchived: string | undefined,
28
  search: string | undefined,
29
  _type: string | undefined,
30
  limit: string | undefined,
31
  offset: string | undefined,
32
  custom: string | undefined,
33
  order_by: string | undefined,
34
  _export: string | undefined,
35
  q: string | undefined,
36
) {
37
  const url = new URL(`https://api.salesflare.com/contacts`);
38
  for (const [k, v] of [
39
    ["id", id],
40
    ["name", name],
41
    ["email", email],
42
    ["phone_number", phone_number],
43
    ["domain", domain],
44
    ["modification_after", modification_after],
45
    ["modification_before", modification_before],
46
    ["creation_after", creation_after],
47
    ["creation_before", creation_before],
48
    ["account", account],
49
    ["tag", tag],
50
    ["tag.name", tag_name],
51
    ["position.role", position_role],
52
    ["address.country", address_country],
53
    ["address.state_region", address_state_region],
54
    ["address.city", address_city],
55
    ["includeArchived", includeArchived],
56
    ["search", search],
57
    ["type", _type],
58
    ["limit", limit],
59
    ["offset", offset],
60
    ["custom", custom],
61
    ["order_by", order_by],
62
    ["export", _export],
63
    ["q", q],
64
  ]) {
65
    if (v !== undefined && v !== "" && k !== undefined) {
66
      url.searchParams.append(k, v);
67
    }
68
  }
69
  const response = await fetch(url, {
70
    method: "GET",
71
    headers: {
72
      Authorization: "Bearer " + auth.apiKey,
73
    },
74
    body: undefined,
75
  });
76
  if (!response.ok) {
77
    const text = await response.text();
78
    throw new Error(`${response.status} ${text}`);
79
  }
80
  return await response.text();
81
}
82