0

Get partners with access to asset

by
Published Dec 20, 2024

Get all the partners the requesting business has granted access to on the given asset. Note: If the asset has been shared with you, an empty array will be returned. This is because an asset shared with you cannot be shared with a different partner.

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 partners with access to asset
7
 * Get all the partners the requesting business has granted access to on the given asset.
8
Note: If the asset has been shared with you, an empty array will be returned. This is because an asset shared with
9
you cannot be shared with a different partner.
10
 */
11
export async function main(
12
  auth: Pinterest,
13
  business_id: string,
14
  asset_id: string,
15
  start_index: string | undefined,
16
  bookmark: string | undefined,
17
  page_size: string | undefined,
18
) {
19
  const url = new URL(
20
    `https://api.pinterest.com/v5/businesses/${business_id}/assets/${asset_id}/partners`,
21
  );
22
  for (const [k, v] of [
23
    ["start_index", start_index],
24
    ["bookmark", bookmark],
25
    ["page_size", page_size],
26
  ]) {
27
    if (v !== undefined && v !== "" && k !== undefined) {
28
      url.searchParams.append(k, v);
29
    }
30
  }
31
  const response = await fetch(url, {
32
    method: "GET",
33
    headers: {
34
      Authorization: "Bearer " + auth.token,
35
    },
36
    body: undefined,
37
  });
38
  if (!response.ok) {
39
    const text = await response.text();
40
    throw new Error(`${response.status} ${text}`);
41
  }
42
  return await response.json();
43
}
44