0
Get project urls aggs
One script reply has been approved by the moderators Verified

Project Query aggregator. It accepts multiple queries that will be executed on all completed analyses in the project

Created by hugo697 239 days ago Viewed 13481 times
0
Submitted by hugo697 Bun
Verified 239 days ago
1
//native
2
type Botify = {
3
  token: string;
4
};
5
/**
6
 * Get project urls aggs
7
 * Project Query aggregator. It accepts multiple queries that will be executed on all completed analyses in the project
8
 */
9
export async function main(
10
  auth: Botify,
11
  username: string,
12
  project_slug: string,
13
  area: string | undefined,
14
  last_analysis_slug: string | undefined,
15
  nb_analyses: string | undefined,
16
) {
17
  const url = new URL(
18
    `https://api.botify.com/projects/${username}/${project_slug}/urls/aggs`,
19
  );
20
  for (const [k, v] of [
21
    ["area", area],
22
    ["last_analysis_slug", last_analysis_slug],
23
    ["nb_analyses", nb_analyses],
24
  ]) {
25
    if (v !== undefined && v !== "" && k !== undefined) {
26
      url.searchParams.append(k, v);
27
    }
28
  }
29
  const response = await fetch(url, {
30
    method: "POST",
31
    headers: {
32
      Authorization: "Token " + auth.token,
33
    },
34
    body: undefined,
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.text();
41
}
42