0

Search user's boards

by
Published Dec 20, 2024

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