1 | import sendgrid from "npm:@sendgrid/client@^7.7.0"; |
2 |
|
3 |
|
4 | * @param on_behalf_of The subuser's username. This header generates the |
5 | * API call as if the subuser account was making the call. |
6 | */ |
7 | type Sendgrid = { |
8 | token: string; |
9 | }; |
10 | export async function main( |
11 | api_token: Sendgrid, |
12 | email: string, |
13 | on_behalf_of?: string, |
14 | ) { |
15 | sendgrid.setApiKey(api_token.token); |
16 | const headers: Record<string, string> = { Accept: "application/json" }; |
17 | if (on_behalf_of) { |
18 | headers["on-behalf-of"] = on_behalf_of; |
19 | } |
20 |
|
21 | const request = { |
22 | url: `/v3/suppression/bounces/${email}`, |
23 | method: "GET", |
24 | headers, |
25 | }; |
26 |
|
27 | try { |
28 | const [_, body] = await sendgrid.request(request); |
29 | return body; |
30 | } catch (error) { |
31 | throw Error("\n" + JSON.stringify(error?.response?.body || error)); |
32 | } |
33 | } |
34 |
|