//native
type Brevo = {
apiKey: string;
};
/**
* Get the list of blocked or unsubscribed transactional contacts
*
*/
export async function main(
auth: Brevo,
startDate: string | undefined,
endDate: string | undefined,
limit: string | undefined,
offset: string | undefined,
senders: string | undefined,
sort: "asc" | "desc" | undefined,
) {
const url = new URL(`https://api.brevo.com/v3/smtp/blockedContacts`);
for (const [k, v] of [
["startDate", startDate],
["endDate", endDate],
["limit", limit],
["offset", offset],
["senders", senders],
["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