Remove Contact From List

Script sendgrid Verified

by saskiaostrmi ยท 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 contact_ids Important: contact IDs are not email addresses.
5
 */
6
type Sendgrid = {
7
  token: string;
8
};
9
export async function main(
10
  api_token: Sendgrid,
11
  list_id: string,
12
  contact_ids: string[],
13
) {
14
  sendgrid.setApiKey(api_token.token);
15

16
  const request = {
17
    url: `/v3/marketing/lists/${list_id}/contacts`,
18
    method: "DELETE",
19
    qs: {
20
      contact_ids: contact_ids?.join(",") || "",
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

Other submissions
  • Submitted by adam186 Deno
    Created 395 days ago
    1
    import sendgrid from "npm:@sendgrid/client@^7.7.0";
    2
    
    
    3
    /**
    4
     * @param contact_ids Important: contact IDs are not email addresses.
    5
     */
    6
    type Sendgrid = {
    7
      token: string;
    8
    };
    9
    export async function main(
    10
      api_token: Sendgrid,
    11
      list_id: string,
    12
      contact_ids: string[],
    13
    ) {
    14
      sendgrid.setApiKey(api_token.token);
    15
    
    
    16
      const request = {
    17
        url: `/v3/marketing/lists/${list_id}/contacts`,
    18
        method: "DELETE",
    19
        qs: {
    20
          contact_ids: contact_ids?.join(",") || "",
    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