0

Update Advertising Unit

by
Published Apr 8, 2025
Script buttondown Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Buttondown = {
3
  token: string;
4
};
5
/**
6
 * Update Advertising Unit
7
 *
8
 */
9
export async function main(
10
  auth: Buttondown,
11
  id: string,
12
  body: {
13
    title?: string;
14
    description?: string;
15
    dates: string[];
16
    behavior?: string;
17
    url?: string;
18
    price?: number;
19
  },
20
) {
21
  const url = new URL(`https://api.buttondown.com/v1/advertising_units/${id}`);
22

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