0

List following boards

by
Published Dec 20, 2024

Get a list of the boards a user follows. The request returns a board summary object array.

Script pinterest Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Pinterest = {
3
  token: string;
4
};
5
/**
6
 * List following boards
7
 * Get a list of the boards a user follows. The request returns a board summary object array.
8
 */
9
export async function main(
10
  auth: Pinterest,
11
  bookmark: string | undefined,
12
  page_size: string | undefined,
13
  explicit_following: string | undefined,
14
  ad_account_id: string | undefined,
15
) {
16
  const url = new URL(
17
    `https://api.pinterest.com/v5/user_account/following/boards`,
18
  );
19
  for (const [k, v] of [
20
    ["bookmark", bookmark],
21
    ["page_size", page_size],
22
    ["explicit_following", explicit_following],
23
    ["ad_account_id", ad_account_id],
24
  ]) {
25
    if (v !== undefined && v !== "" && k !== undefined) {
26
      url.searchParams.append(k, v);
27
    }
28
  }
29
  const response = await fetch(url, {
30
    method: "GET",
31
    headers: {
32
      Authorization: "Bearer " + auth.token,
33
    },
34
    body: undefined,
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42