1 | type Resend = { |
2 | token: string; |
3 | }; |
4 | |
5 | * Update a single contact |
6 | * |
7 | */ |
8 | export async function main( |
9 | auth: Resend, |
10 | id: string, |
11 | audience_id: string, |
12 | body: { |
13 | email?: string; |
14 | first_name?: string; |
15 | last_name?: string; |
16 | unsubscribed?: boolean; |
17 | [k: string]: unknown; |
18 | } |
19 | ) { |
20 | const url = new URL( |
21 | `https://api.resend.com/audiences/${audience_id}/contacts/${id}` |
22 | ); |
23 |
|
24 | const response = await fetch(url, { |
25 | method: "PATCH", |
26 | headers: { |
27 | "Content-Type": "application/json", |
28 | Authorization: "Bearer " + auth.token, |
29 | }, |
30 | body: JSON.stringify(body), |
31 | }); |
32 | if (!response.ok) { |
33 | const text = await response.text(); |
34 | throw new Error(`${response.status} ${text}`); |
35 | } |
36 | return await response.json(); |
37 | } |
38 |
|