0

Get your SMS activity aggregated over a period of time

by
Published Apr 8, 2025
Script brevo Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Brevo = {
3
  apiKey: string;
4
};
5
/**
6
 * Get your SMS activity aggregated over a period of time
7
 *
8
 */
9
export async function main(
10
  auth: Brevo,
11
  startDate: string | undefined,
12
  endDate: string | undefined,
13
  days: string | undefined,
14
  tag: string | undefined,
15
) {
16
  const url = new URL(
17
    `https://api.brevo.com/v3/transactionalSMS/statistics/aggregatedReport`,
18
  );
19
  for (const [k, v] of [
20
    ["startDate", startDate],
21
    ["endDate", endDate],
22
    ["days", days],
23
    ["tag", tag],
24
  ]) {
25
    if (v !== undefined && v !== "" && k !== undefined) {
26
      url.searchParams.append(k, v);
27
    }
28
  }
29
  const response = await fetch(url, {
30
    method: "GET",
31
    headers: {
32
      "api-key": auth.apiKey,
33
    },
34
    body: undefined,
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42