type Asana = {
  token: string;
};
/**
 * Add a collaborator to a goal
 * Adds followers to a goal. Returns the goal the followers were added to.
Each goal can be associated with zero or more followers in the system.
Requests to add/remove followers, if successful, will return the complete updated goal record, described above.
 */
export async function main(
  auth: Asana,
  goal_gid: string,
  opt_pretty: string | undefined,
  opt_fields: string | undefined,
  body: {
    data?: { followers: string[]; [k: string]: unknown };
    [k: string]: unknown;
  }
) {
  const url = new URL(
    `https://app.asana.com/api/1.0/goals/${goal_gid}/addFollowers`
  );
  for (const [k, v] of [
    ["opt_pretty", opt_pretty],
    ["opt_fields", opt_fields],
  ]) {
    if (v !== undefined && v !== "") {
      url.searchParams.append(k, v);
    }
  }
  const response = await fetch(url, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      Authorization: "Bearer " + auth.token,
    },
    body: JSON.stringify(body),
  });
  if (!response.ok) {
    const text = await response.text();
    throw new Error(`${response.status} ${text}`);
  }
  return await response.json();
}
 Submitted by hugo697 181 days ago
type Asana = {
  token: string;
};
/**
 * Add a collaborator to a goal
 * Adds followers to a goal. Returns the goal the followers were added to.
Each goal can be associated with zero or more followers in the system.
Requests to add/remove followers, if successful, will return the complete updated goal record, described above.
 */
export async function main(
  auth: Asana,
  goal_gid: string,
  opt_pretty: string | undefined,
  opt_fields: string | undefined,
  body: {
    data?: { followers: string[]; [k: string]: unknown };
    [k: string]: unknown;
  }
) {
  const url = new URL(
    `https://app.asana.com/api/1.0/goals/${goal_gid}/addFollowers`
  );
  for (const [k, v] of [
    ["opt_pretty", opt_pretty],
    ["opt_fields", opt_fields],
  ]) {
    if (v !== undefined && v !== "") {
      url.searchParams.append(k, v);
    }
  }
  const response = await fetch(url, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      Authorization: "Bearer " + auth.token,
    },
    body: JSON.stringify(body),
  });
  if (!response.ok) {
    const text = await response.text();
    throw new Error(`${response.status} ${text}`);
  }
  return await response.json();
}
 Submitted by hugo697 735 days ago