Get Contact Lists

Script sendgrid Verified

by rubenanitaceballos ยท 6/6/2022

The script

Submitted by hugo989 Bun
Verified 3 days ago
1
import sendgrid from "@sendgrid/client@^7.7.0";
2

3
/**
4
 * @param page_size Maximum number of elements to return. Defaults to 100, returns 1000 max.
5
 *
6
 * @param page_token Token corresponding to a specific page of results.
7
 */
8
type Sendgrid = {
9
  token: string;
10
};
11
export async function main(
12
  api_token: Sendgrid,
13
  page_size?: number,
14
  page_token?: number,
15
) {
16
  sendgrid.setApiKey(api_token.token);
17

18
  const request = {
19
    url: `/v3/marketing/lists`,
20
    method: "GET",
21
    qs: {
22
      page_size,
23
      page_token,
24
    },
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

Other submissions
  • Submitted by adam186 Deno
    Created 395 days ago
    1
    import sendgrid from "npm:@sendgrid/client@^7.7.0";
    2
    
    
    3
    /**
    4
     * @param page_size Maximum number of elements to return. Defaults to 100, returns 1000 max.
    5
     *
    6
     * @param page_token Token corresponding to a specific page of results.
    7
     */
    8
    type Sendgrid = {
    9
      token: string;
    10
    };
    11
    export async function main(
    12
      api_token: Sendgrid,
    13
      page_size?: number,
    14
      page_token?: number,
    15
    ) {
    16
      sendgrid.setApiKey(api_token.token);
    17
    
    
    18
      const request = {
    19
        url: `/v3/marketing/lists`,
    20
        method: "GET",
    21
        qs: {
    22
          page_size,
    23
          page_token,
    24
        },
    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