Edits history of script submission #19974 for ' List tasks (salesflare)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Salesflare = {
      apiKey: string;
    };
    /**
     * List tasks
     *
     */
    export async function main(
      auth: Salesflare,
      id: string | undefined,
      search: string | undefined,
      assignees: string | undefined,
      _type: string | undefined,
      account: string | undefined,
      order_by: string | undefined,
      limit: string | undefined,
      offset: string | undefined,
      _export: string | undefined,
      q: string | undefined,
    ) {
      const url = new URL(`https://api.salesflare.com/tasks`);
      for (const [k, v] of [
        ["id", id],
        ["search", search],
        ["assignees", assignees],
        ["type", _type],
        ["account", account],
        ["order_by", order_by],
        ["limit", limit],
        ["offset", offset],
        ["export", _export],
        ["q", q],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.apiKey,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 235 days ago