0
Get A Contact List
One script reply has been approved by the moderators Verified
Created by adam186 503 days ago Viewed 4106 times
0
Submitted by adam186 Deno
Verified 503 days ago
1
import sendgrid from "npm:@sendgrid/client@^7.7.0";
2

3
/**
4
 * @param contact_sample If `true` then `contact_sample` will be returned with the result.
5
 */
6
type Sendgrid = {
7
  token: string;
8
};
9
export async function main(
10
  api_token: Sendgrid,
11
  list_id: string,
12
  contact_sample?: boolean,
13
) {
14
  sendgrid.setApiKey(api_token.token);
15

16
  const request = {
17
    url: `/v3/marketing/lists/${list_id}`,
18
    method: "GET",
19
    qs: {
20
      contact_sample,
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