0
Get goal relationships
One script reply has been approved by the moderators Verified

Returns compact goal relationship records.

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