0

Get assets assigned to a partner or assets assigned by a partner

by
Published Dec 20, 2024

Can be used to get the business assets your partner has granted you access to or the business assets you have granted your partner access to. If you specify: - partner_type=INTERNAL, you will retrieve your business assets that the partner has access to. - partner_type=EXTERNAL, you will retrieve the partner's business assets that the partner has granted you access to.

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 assets assigned to a partner or assets assigned by a partner
7
 * Can be used to get the business assets your partner has granted you access to or the business assets you have
8
granted your partner access to. If you specify:
9
- partner_type=INTERNAL, you will retrieve your business assets that the partner has access to.
10
- partner_type=EXTERNAL, you will retrieve the partner's business assets that the partner has granted you access to.
11
 */
12
export async function main(
13
  auth: Pinterest,
14
  business_id: string,
15
  partner_id: string,
16
  partner_type: string | undefined,
17
  asset_type: "AD_ACCOUNT" | "PROFILE" | "ASSET_GROUP" | undefined,
18
  start_index: string | undefined,
19
  page_size: string | undefined,
20
  bookmark: string | undefined,
21
) {
22
  const url = new URL(
23
    `https://api.pinterest.com/v5/businesses/${business_id}/partners/${partner_id}/assets`,
24
  );
25
  for (const [k, v] of [
26
    ["partner_type", partner_type],
27
    ["asset_type", asset_type],
28
    ["start_index", start_index],
29
    ["page_size", page_size],
30
    ["bookmark", bookmark],
31
  ]) {
32
    if (v !== undefined && v !== "" && k !== undefined) {
33
      url.searchParams.append(k, v);
34
    }
35
  }
36
  const response = await fetch(url, {
37
    method: "GET",
38
    headers: {
39
      Authorization: "Bearer " + auth.token,
40
    },
41
    body: undefined,
42
  });
43
  if (!response.ok) {
44
    const text = await response.text();
45
    throw new Error(`${response.status} ${text}`);
46
  }
47
  return await response.json();
48
}
49