Get a user's task list

Returns the full record for a user's task list.

Script asana Verified

by hugo697 ยท 10/31/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 383 days ago
1
type Asana = {
2
  token: string;
3
};
4
/**
5
 * Get a user's task list
6
 * Returns the full record for a user's task list.
7
 */
8
export async function main(
9
  auth: Asana,
10
  user_gid: string,
11
  opt_pretty: string | undefined,
12
  opt_fields: string | undefined,
13
  workspace: string | undefined
14
) {
15
  const url = new URL(
16
    `https://app.asana.com/api/1.0/users/${user_gid}/user_task_list`
17
  );
18
  for (const [k, v] of [
19
    ["opt_pretty", opt_pretty],
20
    ["opt_fields", opt_fields],
21
    ["workspace", workspace],
22
  ]) {
23
    if (v !== undefined && v !== "") {
24
      url.searchParams.append(k, v);
25
    }
26
  }
27
  const response = await fetch(url, {
28
    method: "GET",
29
    headers: {
30
      Authorization: "Bearer " + auth.token,
31
    },
32
    body: undefined,
33
  });
34
  if (!response.ok) {
35
    const text = await response.text();
36
    throw new Error(`${response.status} ${text}`);
37
  }
38
  return await response.json();
39
}
40