1 | |
2 | type Brevo = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Fetch all external feeds |
7 | * This endpoint can fetch all created external feeds. |
8 | */ |
9 | export async function main( |
10 | auth: Brevo, |
11 | search: string | undefined, |
12 | startDate: string | undefined, |
13 | endDate: string | undefined, |
14 | sort: "asc" | "desc" | undefined, |
15 | authType: "basic" | "token" | "noAuth" | undefined, |
16 | limit: string | undefined, |
17 | offset: string | undefined, |
18 | ) { |
19 | const url = new URL(`https://api.brevo.com/v3/feeds`); |
20 | for (const [k, v] of [ |
21 | ["search", search], |
22 | ["startDate", startDate], |
23 | ["endDate", endDate], |
24 | ["sort", sort], |
25 | ["authType", authType], |
26 | ["limit", limit], |
27 | ["offset", offset], |
28 | ]) { |
29 | if (v !== undefined && v !== "" && k !== undefined) { |
30 | url.searchParams.append(k, v); |
31 | } |
32 | } |
33 | const response = await fetch(url, { |
34 | method: "GET", |
35 | headers: { |
36 | "api-key": auth.apiKey, |
37 | }, |
38 | body: undefined, |
39 | }); |
40 | if (!response.ok) { |
41 | const text = await response.text(); |
42 | throw new Error(`${response.status} ${text}`); |
43 | } |
44 | return await response.json(); |
45 | } |
46 |
|