Get multiple tasks

Returns the compact task records for some filtered set of tasks. Use one or more of the parameters provided to filter the tasks returned. You must specify a `project` or `tag` if you do not specify `assignee` and `workspace`. For more complex task retrieval, use workspaces/{workspace_gid}/tasks/search.

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 multiple tasks
6
 * Returns the compact task records for some filtered set of tasks. Use one or more of the parameters provided to filter the tasks returned. You must specify a `project` or `tag` if you do not specify `assignee` and `workspace`.
7

8
For more complex task retrieval, use workspaces/{workspace_gid}/tasks/search.
9
 */
10
export async function main(
11
  auth: Asana,
12
  opt_pretty: string | undefined,
13
  opt_fields: string | undefined,
14
  limit: string | undefined,
15
  offset: string | undefined,
16
  assignee: string | undefined,
17
  project: string | undefined,
18
  section: string | undefined,
19
  workspace: string | undefined,
20
  completed_since: string | undefined,
21
  modified_since: string | undefined
22
) {
23
  const url = new URL(`https://app.asana.com/api/1.0/tasks`);
24
  for (const [k, v] of [
25
    ["opt_pretty", opt_pretty],
26
    ["opt_fields", opt_fields],
27
    ["limit", limit],
28
    ["offset", offset],
29
    ["assignee", assignee],
30
    ["project", project],
31
    ["section", section],
32
    ["workspace", workspace],
33
    ["completed_since", completed_since],
34
    ["modified_since", modified_since],
35
  ]) {
36
    if (v !== undefined && v !== "") {
37
      url.searchParams.append(k, v);
38
    }
39
  }
40
  const response = await fetch(url, {
41
    method: "GET",
42
    headers: {
43
      Authorization: "Bearer " + auth.token,
44
    },
45
    body: undefined,
46
  });
47
  if (!response.ok) {
48
    const text = await response.text();
49
    throw new Error(`${response.status} ${text}`);
50
  }
51
  return await response.json();
52
}
53