type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* Get current aggregated analytics
* Retrieves analytics aggregated from the last minute of usage on Spectrum applications underneath a given zone.
*/
export async function main(
auth: Cloudflare,
zone: string,
appID: string | undefined,
app_id_param: string | undefined,
colo_name: string | undefined
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/zones/${zone}/spectrum/analytics/aggregate/current`
);
for (const [k, v] of [
["appID", appID],
["app_id_param", app_id_param],
["colo_name", colo_name],
]) {
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 383 days ago
type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* Get current aggregated analytics
* Retrieves analytics aggregated from the last minute of usage on Spectrum applications underneath a given zone.
*/
export async function main(
auth: Cloudflare,
zone: string,
appID: string | undefined,
app_id_param: string | undefined,
colo_name: string | undefined
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/zones/${zone}/spectrum/analytics/aggregate/current`
);
for (const [k, v] of [
["appID", appID],
["app_id_param", app_id_param],
["colo_name", colo_name],
]) {
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 920 days ago