0

Create a request to export leads collected from a lead ad

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 an export of leads collected from a lead ad. This returns a lead_export_id token that you can use to download the export when it is ready. Note: Lead ad data will be available up to 30 days after the lead has been submitted. 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 a request to export leads collected from a lead ad
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 an export of leads collected from a lead ad. This returns a lead_export_id  token that you can use to download the export when it is ready.
10

11
Note: Lead ad data will be available up to 30 days after the lead has been submitted.
12

13
For more, see Lead ads.
14
 */
15
export async function main(
16
  auth: Pinterest,
17
  ad_account_id: string,
18
  body: { start_date: string; end_date: string; ad_id: string },
19
) {
20
  const url = new URL(
21
    `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/leads_export`,
22
  );
23

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