1 | |
2 | type Attio = { |
3 | token: string; |
4 | }; |
5 | |
6 | * List tasks |
7 | * List all tasks. Results are sorted by creation date, from oldest to newest. |
8 |
|
9 | Required scopes: `task:read`, `object_configuration:read`, `record_permission:read`, `user_management:read`. |
10 | */ |
11 | export async function main( |
12 | auth: Attio, |
13 | limit: string | undefined, |
14 | offset: string | undefined, |
15 | sort: "created_at:asc" | "created_at:desc" | undefined, |
16 | linked_object: string | undefined, |
17 | linked_record_id: string | undefined, |
18 | assignee: string | undefined, |
19 | is_completed: string | undefined, |
20 | ) { |
21 | const url = new URL(`https://api.attio.com/v2/tasks`); |
22 | for (const [k, v] of [ |
23 | ["limit", limit], |
24 | ["offset", offset], |
25 | ["sort", sort], |
26 | ["linked_object", linked_object], |
27 | ["linked_record_id", linked_record_id], |
28 | ["assignee", assignee], |
29 | ["is_completed", is_completed], |
30 | ]) { |
31 | if (v !== undefined && v !== "" && k !== undefined) { |
32 | url.searchParams.append(k, v); |
33 | } |
34 | } |
35 | const response = await fetch(url, { |
36 | method: "GET", |
37 | headers: { |
38 | Authorization: "Bearer " + auth.token, |
39 | }, |
40 | body: undefined, |
41 | }); |
42 | if (!response.ok) { |
43 | const text = await response.text(); |
44 | throw new Error(`${response.status} ${text}`); |
45 | } |
46 | return await response.json(); |
47 | } |
48 |
|