0

Create 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. Create lead forms. Lead forms are used in lead ads and allow you to control what text appears on the lead form’ s description, questions and confirmation sections. 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
 * Create 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
Create lead forms. Lead forms are used in lead ads and allow you to control what text appears on the lead form’ s description, questions and confirmation sections.
10

11
For more, see Lead ads.
12
 */
13
export async function main(
14
  auth: Pinterest,
15
  ad_account_id: string,
16
  body: {
17
    name?: string;
18
    privacy_policy_link?: string;
19
    has_accepted_terms?: false | true;
20
    completion_message?: string;
21
    status?: "DRAFT" | "ACTIVE";
22
    disclosure_language?: string;
23
    questions?: {
24
      question_type?:
25
        | "CUSTOM"
26
        | "FULL_NAME"
27
        | "FIRST_NAME"
28
        | "LAST_NAME"
29
        | "EMAIL"
30
        | "PHONE_NUMBER"
31
        | "ZIP_CODE"
32
        | "GENDER"
33
        | "CITY"
34
        | "COUNTRY"
35
        | "STATE_PROVINCE"
36
        | "ADDRESS"
37
        | "DATE_OF_BIRTH"
38
        | "AGE";
39
      custom_question_field_type?:
40
        | "TEXT_FIELD"
41
        | "TEXT_AREA"
42
        | "RADIO_LIST"
43
        | "CHECKBOX";
44
      custom_question_label?: string;
45
      custom_question_options?: string[];
46
    }[];
47
    policy_links?: { label?: string; link?: string }[];
48
  } & {}[],
49
) {
50
  const url = new URL(
51
    `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/lead_forms`,
52
  );
53

54
  const response = await fetch(url, {
55
    method: "POST",
56
    headers: {
57
      "Content-Type": "application/json",
58
      Authorization: "Bearer " + auth.token,
59
    },
60
    body: JSON.stringify(body),
61
  });
62
  if (!response.ok) {
63
    const text = await response.text();
64
    throw new Error(`${response.status} ${text}`);
65
  }
66
  return await response.json();
67
}
68