type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* Table
* Retrieves a list of summarised aggregate metrics over a given time period.
See [Analytics API properties](https://developers.cloudflare.com/dns/reference/analytics-api-properties/) for detailed information about the available query parameters.
*/
export async function main(
auth: Cloudflare,
identifier: string,
account_identifier: string,
metrics: string | undefined,
dimensions: string | undefined,
since: string | undefined,
until: string | undefined,
limit: string | undefined,
sort: string | undefined,
filters: string | undefined
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/accounts/${account_identifier}/dns_firewall/${identifier}/dns_analytics/report`
);
for (const [k, v] of [
["metrics", metrics],
["dimensions", dimensions],
["since", since],
["until", until],
["limit", limit],
["sort", sort],
["filters", filters],
]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
"X-AUTH-EMAIL": auth.email,
"X-AUTH-KEY": auth.key,
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 426 days ago