//native
type Brevo = {
apiKey: string;
};
/**
* Get all your transactional email activity (unaggregated events)
* This endpoint will show the aggregated stats for past 30 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,
limit: string | undefined,
offset: string | undefined,
startDate: string | undefined,
endDate: string | undefined,
days: string | undefined,
email: string | undefined,
event:
| "bounces"
| "hardBounces"
| "softBounces"
| "delivered"
| "spam"
| "requests"
| "opened"
| "clicks"
| "invalid"
| "deferred"
| "blocked"
| "unsubscribed"
| "error"
| "loadedByProxy"
| undefined,
tags: string | undefined,
messageId: string | undefined,
templateId: string | undefined,
sort: "asc" | "desc" | undefined,
) {
const url = new URL(`https://api.brevo.com/v3/smtp/statistics/events`);
for (const [k, v] of [
["limit", limit],
["offset", offset],
["startDate", startDate],
["endDate", endDate],
["days", days],
["email", email],
["event", event],
["tags", tags],
["messageId", messageId],
["templateId", templateId],
["sort", sort],
]) {
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