1 | |
2 | type Pipedrive = { |
3 | apiToken: string; |
4 | }; |
5 | |
6 | * Get all activities |
7 | * Returns data about all activities. |
8 | */ |
9 | export async function main( |
10 | auth: Pipedrive, |
11 | filter_id: string | undefined, |
12 | ids: string | undefined, |
13 | owner_id: string | undefined, |
14 | deal_id: string | undefined, |
15 | lead_id: string | undefined, |
16 | person_id: string | undefined, |
17 | org_id: string | undefined, |
18 | updated_since: string | undefined, |
19 | updated_until: string | undefined, |
20 | sort_by: "id" | "update_time" | "add_time" | undefined, |
21 | sort_direction: "asc" | "desc" | undefined, |
22 | include_fields: "attendees" | undefined, |
23 | limit: string | undefined, |
24 | cursor: string | undefined, |
25 | ) { |
26 | const url = new URL(`https://api.pipedrive.com/api/v2/activities`); |
27 | for (const [k, v] of [ |
28 | ["filter_id", filter_id], |
29 | ["ids", ids], |
30 | ["owner_id", owner_id], |
31 | ["deal_id", deal_id], |
32 | ["lead_id", lead_id], |
33 | ["person_id", person_id], |
34 | ["org_id", org_id], |
35 | ["updated_since", updated_since], |
36 | ["updated_until", updated_until], |
37 | ["sort_by", sort_by], |
38 | ["sort_direction", sort_direction], |
39 | ["include_fields", include_fields], |
40 | ["limit", limit], |
41 | ["cursor", cursor], |
42 | ]) { |
43 | if (v !== undefined && v !== "" && k !== undefined) { |
44 | url.searchParams.append(k, v); |
45 | } |
46 | } |
47 | const response = await fetch(url, { |
48 | method: "GET", |
49 | headers: { |
50 | "x-api-token": auth.apiToken, |
51 | }, |
52 | body: undefined, |
53 | }); |
54 | if (!response.ok) { |
55 | const text = await response.text(); |
56 | throw new Error(`${response.status} ${text}`); |
57 | } |
58 | return await response.json(); |
59 | } |
60 |
|