0

Update an existing domain

by
Published Mar 6, 2024
Script resend Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 398 days ago
1
type Resend = {
2
  token: string;
3
};
4
/**
5
 * Update an existing domain
6
 *
7
 */
8
export async function main(
9
  auth: Resend,
10
  domain_id: string,
11
  body: {
12
    click_tracking?: boolean;
13
    open_tracking?: boolean;
14
    [k: string]: unknown;
15
  }
16
) {
17
  const url = new URL(`https://api.resend.com/domains/${domain_id}`);
18

19
  const response = await fetch(url, {
20
    method: "PATCH",
21
    headers: {
22
      "Content-Type": "application/json",
23
      Authorization: "Bearer " + auth.token,
24
    },
25
    body: JSON.stringify(body),
26
  });
27
  if (!response.ok) {
28
    const text = await response.text();
29
    throw new Error(`${response.status} ${text}`);
30
  }
31
  return await response.json();
32
}
33