1 | |
2 | type Pipedrive = { |
3 | apiToken: string; |
4 | }; |
5 | |
6 | * Get details of a organization |
7 | * Returns the details of a specific organization. |
8 | */ |
9 | export async function main( |
10 | auth: Pipedrive, |
11 | id: string, |
12 | include_fields: |
13 | | "next_activity_id" |
14 | | "last_activity_id" |
15 | | "open_deals_count" |
16 | | "related_open_deals_count" |
17 | | "closed_deals_count" |
18 | | "related_closed_deals_count" |
19 | | "email_messages_count" |
20 | | "people_count" |
21 | | "activities_count" |
22 | | "done_activities_count" |
23 | | "undone_activities_count" |
24 | | "files_count" |
25 | | "notes_count" |
26 | | "followers_count" |
27 | | "won_deals_count" |
28 | | "related_won_deals_count" |
29 | | "lost_deals_count" |
30 | | "related_lost_deals_count" |
31 | | undefined, |
32 | custom_fields: string | undefined, |
33 | ) { |
34 | const url = new URL(`https://api.pipedrive.com/api/v2/organizations/${id}`); |
35 | for (const [k, v] of [ |
36 | ["include_fields", include_fields], |
37 | ["custom_fields", custom_fields], |
38 | ]) { |
39 | if (v !== undefined && v !== "" && k !== undefined) { |
40 | url.searchParams.append(k, v); |
41 | } |
42 | } |
43 | const response = await fetch(url, { |
44 | method: "GET", |
45 | headers: { |
46 | "x-api-token": auth.apiToken, |
47 | }, |
48 | body: undefined, |
49 | }); |
50 | if (!response.ok) { |
51 | const text = await response.text(); |
52 | throw new Error(`${response.status} ${text}`); |
53 | } |
54 | return await response.json(); |
55 | } |
56 |
|