//native
type Brevo = {
apiKey: string;
};
/**
* Fetch scheduled emails by batchId or messageId
* Fetch scheduled batch of emails by batchId or single scheduled email by messageId (Can retrieve data upto 30 days old)
*/
export async function main(
auth: Brevo,
identifier: string,
startDate: string | undefined,
endDate: string | undefined,
sort: "asc" | "desc" | undefined,
status: "processed" | "inProgress" | "queued" | undefined,
limit: string | undefined,
offset: string | undefined,
) {
const url = new URL(
`https://api.brevo.com/v3/smtp/emailStatus/${identifier}`,
);
for (const [k, v] of [
["startDate", startDate],
["endDate", endDate],
["sort", sort],
["status", status],
["limit", limit],
["offset", offset],
]) {
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