0
Create Contact List
One script reply has been approved by the moderators Verified
Created by paulsjasmin 930 days ago Viewed 9304 times
0
Submitted by adam186 Deno
Verified 751 days ago
1
import sendgrid from "npm:@sendgrid/client@^7.7.0";
2

3
type Sendgrid = {
4
  token: string;
5
};
6
export async function main(api_token: Sendgrid, name: string) {
7
  sendgrid.setApiKey(api_token.token);
8

9
  const request = {
10
    url: `/v3/marketing/lists`,
11
    method: "POST",
12
    body: { name },
13
  };
14

15
  try {
16
    const [_, body] = await sendgrid.request(request);
17
    return body;
18
  } catch (error) {
19
    throw Error("\n" + JSON.stringify(error?.response?.body || error));
20
  }
21
}
22