Create Contact List

Script sendgrid Verified

by paulsjasmin ยท 6/6/2022

The script

Submitted by hugo989 Bun
Verified 3 days ago
1
import sendgrid from "@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

Other submissions
  • Submitted by adam186 Deno
    Created 395 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