0

Get members with access to asset

by
Published Dec 20, 2024

Get all the members the requesting business has granted access to on the given asset.

Script pinterest Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Pinterest = {
3
  token: string;
4
};
5
/**
6
 * Get members with access to asset
7
 * Get all the members the requesting business has granted access to on the given asset.
8
 */
9
export async function main(
10
  auth: Pinterest,
11
  business_id: string,
12
  asset_id: string,
13
  bookmark: string | undefined,
14
  page_size: string | undefined,
15
  start_index: string | undefined,
16
) {
17
  const url = new URL(
18
    `https://api.pinterest.com/v5/businesses/${business_id}/assets/${asset_id}/members`,
19
  );
20
  for (const [k, v] of [
21
    ["bookmark", bookmark],
22
    ["page_size", page_size],
23
    ["start_index", start_index],
24
  ]) {
25
    if (v !== undefined && v !== "" && k !== undefined) {
26
      url.searchParams.append(k, v);
27
    }
28
  }
29
  const response = await fetch(url, {
30
    method: "GET",
31
    headers: {
32
      Authorization: "Bearer " + auth.token,
33
    },
34
    body: undefined,
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42