0

Delete board

by
Published Dec 20, 2024

Delete a board owned by the "operation user_account". - Optional: Business Access: Specify an ad_account_id to use the owner of that ad_account as the "operation user_account". - By default, the "operation user_account" is the token user_account.

Script pinterest Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Pinterest = {
3
  token: string;
4
};
5
/**
6
 * Delete board
7
 * Delete a board owned by the "operation user_account".
8
- Optional: Business Access: Specify an ad_account_id to use the owner of that ad_account as the "operation user_account".
9
- By default, the "operation user_account" is the token user_account.
10
 */
11
export async function main(
12
  auth: Pinterest,
13
  board_id: string,
14
  ad_account_id: string | undefined,
15
) {
16
  const url = new URL(`https://api.pinterest.com/v5/boards/${board_id}`);
17
  for (const [k, v] of [["ad_account_id", ad_account_id]]) {
18
    if (v !== undefined && v !== "" && k !== undefined) {
19
      url.searchParams.append(k, v);
20
    }
21
  }
22
  const response = await fetch(url, {
23
    method: "DELETE",
24
    headers: {
25
      Authorization: "Bearer " + auth.token,
26
    },
27
    body: undefined,
28
  });
29
  if (!response.ok) {
30
    const text = await response.text();
31
    throw new Error(`${response.status} ${text}`);
32
  }
33
  return await response.json();
34
}
35