0

Get the lead export from the lead export create call

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. Get the export of leads collected from a lead ad. This returns a URL to a list of lead export given a lead_export_id token returned from the create a lead export call. You can use the URL to download the report. 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
 * Get the lead export from the lead export create call
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
Get the export of leads collected from a lead ad. This returns a URL to a list of lead export given a lead_export_id token returned from the create a lead export call. You can use the URL to download the report.
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
  leads_export_id: string,
19
) {
20
  const url = new URL(
21
    `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/leads_export/${leads_export_id}`,
22
  );
23

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