0

List lead forms

by
Published Dec 20, 2024

This feature is currently in beta and not available to all apps, if you're interested in joining the beta, please reach out to your Pinterest account manager. List lead forms associated with an ad account ID. For more, see Lead ads.

Script pinterest Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Pinterest = {
3
  token: string;
4
};
5
/**
6
 * List lead forms
7
 * This feature is currently in beta and not available to all apps, if you're interested in joining the beta, please reach out to your Pinterest account manager.
8

9
List lead forms associated with an ad account ID.
10

11
For more, see Lead ads.
12
 */
13
export async function main(
14
  auth: Pinterest,
15
  ad_account_id: string,
16
  page_size: string | undefined,
17
  order: "ASCENDING" | "DESCENDING" | undefined,
18
  bookmark: string | undefined,
19
) {
20
  const url = new URL(
21
    `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/lead_forms`,
22
  );
23
  for (const [k, v] of [
24
    ["page_size", page_size],
25
    ["order", order],
26
    ["bookmark", bookmark],
27
  ]) {
28
    if (v !== undefined && v !== "" && k !== undefined) {
29
      url.searchParams.append(k, v);
30
    }
31
  }
32
  const response = await fetch(url, {
33
    method: "GET",
34
    headers: {
35
      Authorization: "Bearer " + auth.token,
36
    },
37
    body: undefined,
38
  });
39
  if (!response.ok) {
40
    const text = await response.text();
41
    throw new Error(`${response.status} ${text}`);
42
  }
43
  return await response.json();
44
}
45