0

Get lead ads subscriptions

by
Published Dec 20, 2024

Get the advertiser's list of lead ads subscriptions. - Only requests for the OWNER or ADMIN of the ad_account will be allowed. This endpoint is currently in beta and not 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 lead ads subscriptions
7
 * Get the advertiser's list of lead ads subscriptions.
8
- Only requests for the OWNER or ADMIN of the ad_account will be allowed.
9

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