type Asana = {
  token: string;
};
/**
 * Get tasks from a user task list
 * Returns the compact list of tasks in a user’s My Tasks list.
 *Note: Access control is enforced for this endpoint as with all Asana API endpoints, meaning a user’s private tasks will be filtered out if the API-authenticated user does not have access to them.*
 *Note: Both complete and incomplete tasks are returned by default unless they are filtered out (for example, setting `completed_since=now` will return only incomplete tasks, which is the default view for “My Tasks” in Asana.)*
 */
export async function main(
  auth: Asana,
  user_task_list_gid: string,
  completed_since: string | undefined,
  opt_pretty: string | undefined,
  opt_fields: string | undefined,
  limit: string | undefined,
  offset: string | undefined
) {
  const url = new URL(
    `https://app.asana.com/api/1.0/user_task_lists/${user_task_list_gid}/tasks`
  );
  for (const [k, v] of [
    ["completed_since", completed_since],
    ["opt_pretty", opt_pretty],
    ["opt_fields", opt_fields],
    ["limit", limit],
    ["offset", offset],
  ]) {
    if (v !== undefined && v !== "") {
      url.searchParams.append(k, v);
    }
  }
  const response = await fetch(url, {
    method: "GET",
    headers: {
      Authorization: "Bearer " + auth.token,
    },
    body: undefined,
  });
  if (!response.ok) {
    const text = await response.text();
    throw new Error(`${response.status} ${text}`);
  }
  return await response.json();
}
Submitted by hugo697 178 days ago
type Asana = {
  token: string;
};
/**
 * Get tasks from a user task list
 * Returns the compact list of tasks in a user’s My Tasks list.
 *Note: Access control is enforced for this endpoint as with all Asana API endpoints, meaning a user’s private tasks will be filtered out if the API-authenticated user does not have access to them.*
 *Note: Both complete and incomplete tasks are returned by default unless they are filtered out (for example, setting `completed_since=now` will return only incomplete tasks, which is the default view for “My Tasks” in Asana.)*
 */
export async function main(
  auth: Asana,
  user_task_list_gid: string,
  completed_since: string | undefined,
  opt_pretty: string | undefined,
  opt_fields: string | undefined,
  limit: string | undefined,
  offset: string | undefined
) {
  const url = new URL(
    `https://app.asana.com/api/1.0/user_task_lists/${user_task_list_gid}/tasks`
  );
  for (const [k, v] of [
    ["completed_since", completed_since],
    ["opt_pretty", opt_pretty],
    ["opt_fields", opt_fields],
    ["limit", limit],
    ["offset", offset],
  ]) {
    if (v !== undefined && v !== "") {
      url.searchParams.append(k, v);
    }
  }
  const response = await fetch(url, {
    method: "GET",
    headers: {
      Authorization: "Bearer " + auth.token,
    },
    body: undefined,
  });
  if (!response.ok) {
    const text = await response.text();
    throw new Error(`${response.status} ${text}`);
  }
  return await response.json();
}
Submitted by hugo697 732 days ago