0

List boards

by
Published Dec 20, 2024

Get a list of the boards owned by the "operation user_account" + group boards where this account is a collaborator Optional: Business Access: Specify an ad_account_id to use the owner of that ad_account as the "operation user_account". Optional: Specify a privacy type (public, protected, or secret) to indicate which boards to return. - If no privacy is specified, all boards that can be returned (based on the scopes of the token and ad_account role if applicable) will be returned.

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 boards
7
 * Get a list of the boards owned by the "operation user_account" + group boards where this account is a collaborator
8
Optional: Business Access: Specify an ad_account_id to use the owner of that ad_account as the "operation user_account".
9
Optional: Specify a privacy type (public, protected, or secret) to indicate which boards to return.
10
- If no privacy is specified, all boards that can be returned (based on the scopes of the token and ad_account role if applicable) will be returned.
11
 */
12
export async function main(
13
  auth: Pinterest,
14
  ad_account_id: string | undefined,
15
  bookmark: string | undefined,
16
  page_size: string | undefined,
17
  privacy:
18
    | "ALL"
19
    | "PROTECTED"
20
    | "PUBLIC"
21
    | "SECRET"
22
    | "PUBLIC_AND_SECRET"
23
    | undefined,
24
) {
25
  const url = new URL(`https://api.pinterest.com/v5/boards`);
26
  for (const [k, v] of [
27
    ["ad_account_id", ad_account_id],
28
    ["bookmark", bookmark],
29
    ["page_size", page_size],
30
    ["privacy", privacy],
31
  ]) {
32
    if (v !== undefined && v !== "" && k !== undefined) {
33
      url.searchParams.append(k, v);
34
    }
35
  }
36
  const response = await fetch(url, {
37
    method: "GET",
38
    headers: {
39
      Authorization: "Bearer " + auth.token,
40
    },
41
    body: undefined,
42
  });
43
  if (!response.ok) {
44
    const text = await response.text();
45
    throw new Error(`${response.status} ${text}`);
46
  }
47
  return await response.json();
48
}
49