0

Get catalogs report

by
Published Dec 20, 2024

This returns a URL to a report given a token returned from Build catalogs report. You can use the URL to download the report. - By default, the "operation user_account" is the token user_account. Optional: Business Access: Specify an ad_account_id (obtained via List ad accounts) to use the owner of that ad_account as the "operation user_account". In order to do this, the token user_account must have one of the following Business Access roles on the ad_account: Owner, Admin, Catalogs Manager.

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 catalogs report
7
 * This returns a URL to a report given a token returned from Build catalogs report. You can use the URL to download the report.
8
- By default, the "operation user_account" is the token user_account.
9

10
Optional: Business Access: Specify an ad_account_id (obtained via List ad accounts) to use the owner of that ad_account as the "operation user_account". In order to do this, the token user_account must have one of the following Business Access roles on the ad_account: Owner, Admin, Catalogs Manager.
11
 */
12
export async function main(
13
  auth: Pinterest,
14
  ad_account_id: string | undefined,
15
  token: string | undefined,
16
) {
17
  const url = new URL(`https://api.pinterest.com/v5/catalogs/reports`);
18
  for (const [k, v] of [
19
    ["ad_account_id", ad_account_id],
20
    ["token", token],
21
  ]) {
22
    if (v !== undefined && v !== "" && k !== undefined) {
23
      url.searchParams.append(k, v);
24
    }
25
  }
26
  const response = await fetch(url, {
27
    method: "GET",
28
    headers: {
29
      Authorization: "Bearer " + auth.token,
30
    },
31
    body: undefined,
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39