0
Get Contact Lists
One script reply has been approved by the moderators Verified
Created by rubenanitaceballos 930 days ago Viewed 9286 times
0
Submitted by adam186 Deno
Verified 751 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