0

Update board section

by
Published Dec 20, 2024

Update a board section on a board owned by the "operation user_account" - or on a group board that has been shared with this 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
 * Update board section
7
 * Update a board section on a board owned by the "operation user_account" - or on a group board that has been shared with this 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
  section_id: string,
15
  ad_account_id: string | undefined,
16
  body: { id?: string; name: string },
17
) {
18
  const url = new URL(
19
    `https://api.pinterest.com/v5/boards/${board_id}/sections/${section_id}`,
20
  );
21
  for (const [k, v] of [["ad_account_id", ad_account_id]]) {
22
    if (v !== undefined && v !== "" && k !== undefined) {
23
      url.searchParams.append(k, v);
24
    }
25
  }
26
  const response = await fetch(url, {
27
    method: "PATCH",
28
    headers: {
29
      "Content-Type": "application/json",
30
      Authorization: "Bearer " + auth.token,
31
    },
32
    body: JSON.stringify(body),
33
  });
34
  if (!response.ok) {
35
    const text = await response.text();
36
    throw new Error(`${response.status} ${text}`);
37
  }
38
  return await response.json();
39
}
40