0

Retrieve a single contact

by
Published Mar 6, 2024
Script resend Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 399 days ago
1
type Resend = {
2
  token: string;
3
};
4
/**
5
 * Retrieve a single contact
6
 *
7
 */
8
export async function main(auth: Resend, id: string, audience_id: string) {
9
  const url = new URL(
10
    `https://api.resend.com/audiences/${audience_id}/contacts/${id}`
11
  );
12

13
  const response = await fetch(url, {
14
    method: "GET",
15
    headers: {
16
      Authorization: "Bearer " + auth.token,
17
    },
18
    body: undefined,
19
  });
20
  if (!response.ok) {
21
    const text = await response.text();
22
    throw new Error(`${response.status} ${text}`);
23
  }
24
  return await response.json();
25
}
26