0

List Pins

by
Published Dec 20, 2024

Get a list of the Pins owned by the "operation 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
7
 * Get a list of the Pins owned by the "operation user_account".
8
 */
9
export async function main(
10
  auth: Pinterest,
11
  bookmark: string | undefined,
12
  page_size: string | undefined,
13
  pin_filter:
14
    | "exclude_native"
15
    | "exclude_repins"
16
    | "has_been_promoted"
17
    | undefined,
18
  include_protected_pins: string | undefined,
19
  pin_type: "PRIVATE" | undefined,
20
  creative_types: string | undefined,
21
  ad_account_id: string | undefined,
22
  pin_metrics: string | undefined,
23
) {
24
  const url = new URL(`https://api.pinterest.com/v5/pins`);
25
  for (const [k, v] of [
26
    ["bookmark", bookmark],
27
    ["page_size", page_size],
28
    ["pin_filter", pin_filter],
29
    ["include_protected_pins", include_protected_pins],
30
    ["pin_type", pin_type],
31
    ["creative_types", creative_types],
32
    ["ad_account_id", ad_account_id],
33
    ["pin_metrics", pin_metrics],
34
  ]) {
35
    if (v !== undefined && v !== "" && k !== undefined) {
36
      url.searchParams.append(k, v);
37
    }
38
  }
39
  const response = await fetch(url, {
40
    method: "GET",
41
    headers: {
42
      Authorization: "Bearer " + auth.token,
43
    },
44
    body: undefined,
45
  });
46
  if (!response.ok) {
47
    const text = await response.text();
48
    throw new Error(`${response.status} ${text}`);
49
  }
50
  return await response.json();
51
}
52