0

List Pins on board

by
Published Dec 20, 2024

Get a list of the Pins 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
 * List Pins on board
7
 * Get a list of the Pins 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
  bookmark: string | undefined,
15
  page_size: string | undefined,
16
  creative_types: string | undefined,
17
  ad_account_id: string | undefined,
18
  pin_metrics: string | undefined,
19
) {
20
  const url = new URL(`https://api.pinterest.com/v5/boards/${board_id}/pins`);
21
  for (const [k, v] of [
22
    ["bookmark", bookmark],
23
    ["page_size", page_size],
24
    ["creative_types", creative_types],
25
    ["ad_account_id", ad_account_id],
26
    ["pin_metrics", pin_metrics],
27
  ]) {
28
    if (v !== undefined && v !== "" && k !== undefined) {
29
      url.searchParams.append(k, v);
30
    }
31
  }
32
  const response = await fetch(url, {
33
    method: "GET",
34
    headers: {
35
      Authorization: "Bearer " + auth.token,
36
    },
37
    body: undefined,
38
  });
39
  if (!response.ok) {
40
    const text = await response.text();
41
    throw new Error(`${response.status} ${text}`);
42
  }
43
  return await response.json();
44
}
45