//native
type Brevo = {
apiKey: string;
};
/**
* Get attribution metrics for one or more Brevo campaigns or workflows
*
*/
export async function main(
auth: Brevo,
periodFrom: string | undefined,
periodTo: string | undefined,
emailCampaignId__: string | undefined,
smsCampaignId__: string | undefined,
automationWorkflowEmailId__: string | undefined,
automationWorkflowSmsId__: string | undefined,
) {
const url = new URL(`https://api.brevo.com/v3/ecommerce/attribution/metrics`);
for (const [k, v] of [
["periodFrom", periodFrom],
["periodTo", periodTo],
["emailCampaignId[]", emailCampaignId__],
["smsCampaignId[]", smsCampaignId__],
["automationWorkflowEmailId[]", automationWorkflowEmailId__],
["automationWorkflowSmsId[]", automationWorkflowSmsId__],
]) {
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