//native
type Brevo = {
apiKey: string;
};
/**
* Get your transactional email activity aggregated over a period of time
* This endpoint will show the aggregated stats for past 90 days by default if `startDate` and `endDate` OR `days` is not passed. The date range can not exceed 90 days
*/
export async function main(
auth: Brevo,
startDate: string | undefined,
endDate: string | undefined,
days: string | undefined,
tag: string | undefined,
) {
const url = new URL(
`https://api.brevo.com/v3/smtp/statistics/aggregatedReport`,
);
for (const [k, v] of [
["startDate", startDate],
["endDate", endDate],
["days", days],
["tag", tag],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
"api-key": auth.apiKey,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 428 days ago