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

Returns the full record for a user task list.

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