0

Search user's Pins

by
Published Dec 20, 2024

Search for pins for the "operation user_account". - By default, the "operation user_account" is the token user_account. If using Business Access: Specify an ad_account_id to use the owner of that ad_account as the "operation user_account". See Understanding Business Access for more information.

Script pinterest Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Pinterest = {
3
  token: string;
4
};
5
/**
6
 * Search user's Pins
7
 * Search for pins for the "operation user_account".
8
- By default, the "operation user_account" is the token user_account.
9

10
If using Business Access: Specify an ad_account_id to use the owner of that ad_account as the "operation user_account". See Understanding Business Access for more information.
11
 */
12
export async function main(
13
  auth: Pinterest,
14
  ad_account_id: string | undefined,
15
  query: string | undefined,
16
  bookmark: string | undefined,
17
) {
18
  const url = new URL(`https://api.pinterest.com/v5/search/pins`);
19
  for (const [k, v] of [
20
    ["ad_account_id", ad_account_id],
21
    ["query", query],
22
    ["bookmark", bookmark],
23
  ]) {
24
    if (v !== undefined && v !== "" && k !== undefined) {
25
      url.searchParams.append(k, v);
26
    }
27
  }
28
  const response = await fetch(url, {
29
    method: "GET",
30
    headers: {
31
      Authorization: "Bearer " + auth.token,
32
    },
33
    body: undefined,
34
  });
35
  if (!response.ok) {
36
    const text = await response.text();
37
    throw new Error(`${response.status} ${text}`);
38
  }
39
  return await response.json();
40
}
41