Edits history of script submission #9454 for ' Get project urls aggs (botify)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Botify = {
      token: string;
    };
    /**
     * Get project urls aggs
     * Project Query aggregator. It accepts multiple queries that will be executed on all completed analyses in the project
     */
    export async function main(
      auth: Botify,
      username: string,
      project_slug: string,
      area: string | undefined,
      last_analysis_slug: string | undefined,
      nb_analyses: string | undefined,
    ) {
      const url = new URL(
        `https://api.botify.com/projects/${username}/${project_slug}/urls/aggs`,
      );
      for (const [k, v] of [
        ["area", area],
        ["last_analysis_slug", last_analysis_slug],
        ["nb_analyses", nb_analyses],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "POST",
        headers: {
          Authorization: "Token " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 566 days ago