0

Create lead form test data

by
Published Dec 20, 2024

Create lead form test data based on the list of answers provided as part of the body. - List of answers should follow the questions creation order. 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
 * Create lead form test data
7
 * Create lead form test data based on the list of answers provided as part of the body.
8
- List of answers should follow the questions creation order.
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
  lead_form_id: string,
16
  body: { answers: string[] },
17
) {
18
  const url = new URL(
19
    `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/lead_forms/${lead_form_id}/test`,
20
  );
21

22
  const response = await fetch(url, {
23
    method: "POST",
24
    headers: {
25
      "Content-Type": "application/json",
26
      Authorization: "Bearer " + auth.token,
27
    },
28
    body: JSON.stringify(body),
29
  });
30
  if (!response.ok) {
31
    const text = await response.text();
32
    throw new Error(`${response.status} ${text}`);
33
  }
34
  return await response.json();
35
}
36