1 | import sendgrid from "npm:@sendgrid/client@^7.7.0"; |
2 |
|
3 |
|
4 | * @param contact_ids Important: contact IDs are not email addresses. |
5 | */ |
6 | type Sendgrid = { |
7 | token: string; |
8 | }; |
9 | export async function main( |
10 | api_token: Sendgrid, |
11 | list_id: string, |
12 | contact_ids: string[], |
13 | ) { |
14 | sendgrid.setApiKey(api_token.token); |
15 |
|
16 | const request = { |
17 | url: `/v3/marketing/lists/${list_id}/contacts`, |
18 | method: "DELETE", |
19 | qs: { |
20 | contact_ids: contact_ids?.join(",") || "", |
21 | }, |
22 | }; |
23 |
|
24 | try { |
25 | const [_, body] = await sendgrid.request(request); |
26 | return body; |
27 | } catch (error) { |
28 | throw Error("\n" + JSON.stringify(error?.response?.body || error)); |
29 | } |
30 | } |
31 |
|