0

Create board

by
Published Dec 20, 2024

Create 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
 * Create board
7
 * Create 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
  ad_account_id: string | undefined,
14
  body: {
15
    id?: string;
16
    created_at?: string;
17
    board_pins_modified_at?: string;
18
    name: string;
19
    description?: string;
20
    collaborator_count?: number;
21
    pin_count?: number;
22
    follower_count?: number;
23
    media?: { image_cover_url?: string; pin_thumbnail_urls?: string[] };
24
    owner?: { username?: string };
25
    privacy?: "PUBLIC" | "PROTECTED" | "SECRET";
26
  },
27
) {
28
  const url = new URL(`https://api.pinterest.com/v5/boards`);
29
  for (const [k, v] of [["ad_account_id", ad_account_id]]) {
30
    if (v !== undefined && v !== "" && k !== undefined) {
31
      url.searchParams.append(k, v);
32
    }
33
  }
34
  const response = await fetch(url, {
35
    method: "POST",
36
    headers: {
37
      "Content-Type": "application/json",
38
      Authorization: "Bearer " + auth.token,
39
    },
40
    body: JSON.stringify(body),
41
  });
42
  if (!response.ok) {
43
    const text = await response.text();
44
    throw new Error(`${response.status} ${text}`);
45
  }
46
  return await response.json();
47
}
48