0
Get results for a URL scan
One script reply has been approved by the moderators Verified
Created by hugo697 254 days ago Viewed 8904 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 254 days ago
1
type Cloudflare = {
2
  token: string;
3
  email: string;
4
  key: string;
5
};
6
/**
7
 * Get results for a URL scan
8
 *
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  account_identifier: string,
13
  url_id_param: string | undefined,
14
  url: string | undefined
15
) {
16
  const url_ = new URL(
17
    `https://api.cloudflare.com/client/v4/accounts/${account_identifier}/brand-protection/url-info`
18
  );
19
  for (const [k, v] of [
20
    ["url_id_param", url_id_param],
21
    ["url", url],
22
  ]) {
23
    if (v !== undefined && v !== "") {
24
      url_.searchParams.append(k, v);
25
    }
26
  }
27
  const response = await fetch(url_, {
28
    method: "GET",
29
    headers: {
30
      "X-AUTH-EMAIL": auth.email,
31
      "X-AUTH-KEY": auth.key,
32
      Authorization: "Bearer " + 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.json();
41
}
42