0
Get tasks from a user task list
One script reply has been approved by the moderators Verified

Returns the compact list of tasks in a user’s My Tasks list. Note: Access control is enforced for this endpoint as with all Asana API endpoints, meaning a user’s private tasks will be filtered out if the API-authenticated user does not have access to them. Note: Both complete and incomplete tasks are returned by default unless they are filtered out (for example, setting completed_since=now will return only incomplete tasks, which is the default view for “My Tasks” in Asana.)

Created by hugo697 313 days ago Viewed 8958 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 313 days ago
1
type Asana = {
2
  token: string;
3
};
4
/**
5
 * Get tasks from a user task list
6
 * Returns the compact list of tasks in a user’s My Tasks list.
7
 *Note: Access control is enforced for this endpoint as with all Asana API endpoints, meaning a user’s private tasks will be filtered out if the API-authenticated user does not have access to them.*
8
 *Note: Both complete and incomplete tasks are returned by default unless they are filtered out (for example, setting `completed_since=now` will return only incomplete tasks, which is the default view for “My Tasks” in Asana.)*
9
 */
10
export async function main(
11
  auth: Asana,
12
  user_task_list_gid: string,
13
  completed_since: string | undefined,
14
  opt_pretty: string | undefined,
15
  opt_fields: string | undefined,
16
  limit: string | undefined,
17
  offset: string | undefined
18
) {
19
  const url = new URL(
20
    `https://app.asana.com/api/1.0/user_task_lists/${user_task_list_gid}/tasks`
21
  );
22
  for (const [k, v] of [
23
    ["completed_since", completed_since],
24
    ["opt_pretty", opt_pretty],
25
    ["opt_fields", opt_fields],
26
    ["limit", limit],
27
    ["offset", offset],
28
  ]) {
29
    if (v !== undefined && v !== "") {
30
      url.searchParams.append(k, v);
31
    }
32
  }
33
  const response = await fetch(url, {
34
    method: "GET",
35
    headers: {
36
      Authorization: "Bearer " + auth.token,
37
    },
38
    body: undefined,
39
  });
40
  if (!response.ok) {
41
    const text = await response.text();
42
    throw new Error(`${response.status} ${text}`);
43
  }
44
  return await response.json();
45
}
46