0

Get Task

by
Published Oct 31, 2023

Get the full record of a task by its gid. Use `opt_fields` (comma-separated, e.g. `name,assignee.name,custom_fields`) to choose the returned fields.

Script asana Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 2 hours ago
1
//native
2

3
/**
4
 * Get Task
5
 * Get the full record of a task by its gid. Use `opt_fields` (comma-separated, e.g. `name,assignee.name,custom_fields`) to choose the returned fields.
6
 */
7
export async function main(
8
  auth: RT.Asana,
9
  task_gid: string,
10
  opt_fields: string | undefined
11
) {
12
  const url = new URL(`https://app.asana.com/api/1.0/tasks/${task_gid}`)
13
  if (opt_fields != null && opt_fields !== "") {
14
    url.searchParams.append("opt_fields", opt_fields)
15
  }
16

17
  const response = await fetch(url, {
18
    headers: {
19
      Authorization: `Bearer ${auth.token}`,
20
      Accept: "application/json",
21
    },
22
  })
23

24
  if (!response.ok) {
25
    throw new Error(`${response.status} ${await response.text()}`)
26
  }
27

28
  return await response.json()
29
}
30

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