0
Get a story
One script reply has been approved by the moderators Verified

Returns the full record for a single story.

Created by hugo697 418 days ago Viewed 9155 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 418 days ago
1
type Asana = {
2
  token: string;
3
};
4
/**
5
 * Get a story
6
 * Returns the full record for a single story.
7
 */
8
export async function main(
9
  auth: Asana,
10
  story_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(`https://app.asana.com/api/1.0/stories/${story_gid}`);
17
  for (const [k, v] of [
18
    ["opt_pretty", opt_pretty],
19
    ["opt_fields", opt_fields],
20
    ["limit", limit],
21
    ["offset", offset],
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