0

Get billing profiles

by
Published Dec 20, 2024

Get billing profiles in the advertiser account. This endpoint might not be available to all apps. Learn more.

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 billing profiles
7
 * Get billing profiles in the advertiser account.
8

9
This endpoint might not be available to all apps. Learn more.
10
 */
11
export async function main(
12
  auth: Pinterest,
13
  ad_account_id: string,
14
  is_active: string | undefined,
15
  bookmark: string | undefined,
16
  page_size: string | undefined,
17
) {
18
  const url = new URL(
19
    `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/billing_profiles`,
20
  );
21
  for (const [k, v] of [
22
    ["is_active", is_active],
23
    ["bookmark", bookmark],
24
    ["page_size", page_size],
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