0
Get stories from a task
One script reply has been approved by the moderators Verified

Returns the compact records for all stories on the task.

Created by hugo697 192 days ago Viewed 5957 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 192 days ago
1
type Asana = {
2
  token: string;
3
};
4
/**
5
 * Get stories from a task
6
 * Returns the compact records for all stories on the 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
  limit: string | undefined,
14
  offset: string | undefined
15
) {
16
  const url = new URL(
17
    `https://app.asana.com/api/1.0/tasks/${task_gid}/stories`
18
  );
19
  for (const [k, v] of [
20
    ["opt_pretty", opt_pretty],
21
    ["opt_fields", opt_fields],
22
    ["limit", limit],
23
    ["offset", offset],
24
  ]) {
25
    if (v !== undefined && v !== "") {
26
      url.searchParams.append(k, v);
27
    }
28
  }
29
  const response = await fetch(url, {
30
    method: "GET",
31
    headers: {
32
      Authorization: "Bearer " + auth.token,
33
    },
34
    body: undefined,
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42