1 | |
2 | type Salesflare = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * List opportunities |
7 | * default date filter (from/to) is on close_datesetting scope to user gives back all opportunities from the user |
8 | */ |
9 | export async function main( |
10 | auth: Salesflare, |
11 | search: string | undefined, |
12 | id: string | undefined, |
13 | name: string | undefined, |
14 | status: string | undefined, |
15 | stage: string | undefined, |
16 | stage_name: string | undefined, |
17 | owner: string | undefined, |
18 | team_member: string | undefined, |
19 | owner_group: string | undefined, |
20 | assignee_group: string | undefined, |
21 | team_member_group: string | undefined, |
22 | account: string | undefined, |
23 | assignee: string | undefined, |
24 | min_value: string | undefined, |
25 | max_value: string | undefined, |
26 | close_after: string | undefined, |
27 | close_before: string | undefined, |
28 | creation_after: string | undefined, |
29 | creation_before: string | undefined, |
30 | closed: string | undefined, |
31 | done: string | undefined, |
32 | tag: string | undefined, |
33 | tag_name: string | undefined, |
34 | hotness: string | undefined, |
35 | limit: string | undefined, |
36 | offset: string | undefined, |
37 | order_by: string | undefined, |
38 | pipeline: string | undefined, |
39 | custom: string | undefined, |
40 | details: string | undefined, |
41 | _export: string | undefined, |
42 | q: string | undefined, |
43 | ) { |
44 | const url = new URL(`https://api.salesflare.com/opportunities`); |
45 | for (const [k, v] of [ |
46 | ["search", search], |
47 | ["id", id], |
48 | ["name", name], |
49 | ["status", status], |
50 | ["stage", stage], |
51 | ["stage.name", stage_name], |
52 | ["owner", owner], |
53 | ["team_member", team_member], |
54 | ["owner_group", owner_group], |
55 | ["assignee_group", assignee_group], |
56 | ["team_member_group", team_member_group], |
57 | ["account", account], |
58 | ["assignee", assignee], |
59 | ["min_value", min_value], |
60 | ["max_value", max_value], |
61 | ["close_after", close_after], |
62 | ["close_before", close_before], |
63 | ["creation_after", creation_after], |
64 | ["creation_before", creation_before], |
65 | ["closed", closed], |
66 | ["done", done], |
67 | ["tag", tag], |
68 | ["tag.name", tag_name], |
69 | ["hotness", hotness], |
70 | ["limit", limit], |
71 | ["offset", offset], |
72 | ["order_by", order_by], |
73 | ["pipeline", pipeline], |
74 | ["custom", custom], |
75 | ["details", details], |
76 | ["export", _export], |
77 | ["q", q], |
78 | ]) { |
79 | if (v !== undefined && v !== "" && k !== undefined) { |
80 | url.searchParams.append(k, v); |
81 | } |
82 | } |
83 | const response = await fetch(url, { |
84 | method: "GET", |
85 | headers: { |
86 | Authorization: "Bearer " + auth.apiKey, |
87 | }, |
88 | body: undefined, |
89 | }); |
90 | if (!response.ok) { |
91 | const text = await response.text(); |
92 | throw new Error(`${response.status} ${text}`); |
93 | } |
94 | return await response.text(); |
95 | } |
96 |
|