0

Create a request for a Marketing Mix Modeling (MMM) report

by
Published Dec 20, 2024

This creates an asynchronous mmm report based on the given request. It returns a token that you can use to download the report when it is ready. NOTE: An additional limit of 5 queries per minute per advertiser applies to this endpoint while it's in beta release.

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 for a Marketing Mix Modeling (MMM) report
7
 * This creates an asynchronous mmm report based on the given request. It returns a token that you can use to download
8
the report when it is ready. NOTE: An additional limit of 5 queries per minute per advertiser applies to this endpoint while it's in beta release.
9
 */
10
export async function main(
11
  auth: Pinterest,
12
  ad_account_id: string,
13
  body: {
14
    countries?:
15
      | "US"
16
      | "GB"
17
      | "CA"
18
      | "IE"
19
      | "AU"
20
      | "NZ"
21
      | "FR"
22
      | "SE"
23
      | "IL"
24
      | "DE"
25
      | "AT"
26
      | "IT"
27
      | "ES"
28
      | "NL"
29
      | "BE"
30
      | "PT"
31
      | "CH"
32
      | "HK"
33
      | "JP"
34
      | "KR"
35
      | "SG"
36
      | "NO"
37
      | "DK"
38
      | "FI"
39
      | "CY"
40
      | "LU"
41
      | "MT"
42
      | "PL"
43
      | "RO"
44
      | "HU"
45
      | "CZ"
46
      | "GR"
47
      | "SK"
48
      | "BR"
49
      | "MX"
50
      | "AR"
51
      | "CL"
52
      | "CO"[];
53
  } & {
54
    report_name: string;
55
    start_date: string;
56
    end_date: string;
57
    granularity: "DAY" | "WEEK";
58
    level: "CAMPAIGN_TARGETING" | "AD_GROUP_TARGETING";
59
    targeting_types:
60
      | "APPTYPE"
61
      | "COUNTRY"
62
      | "CREATIVE_TYPE"
63
      | "GENDER"
64
      | "LOCATION"[];
65
    columns:
66
      | "SPEND_IN_DOLLAR"
67
      | "SPEND_IN_MICRO_DOLLAR"
68
      | "ECPC_IN_DOLLAR"
69
      | "ECTR"
70
      | "CAMPAIGN_NAME"
71
      | "TOTAL_ENGAGEMENT"
72
      | "EENGAGEMENT_RATE"
73
      | "ECPM_IN_DOLLAR"
74
      | "CAMPAIGN_ID"
75
      | "ADVERTISER_ID"
76
      | "AD_GROUP_ID"
77
      | "AD_GROUP_NAME"
78
      | "CLICKTHROUGH_1"
79
      | "IMPRESSION_1"
80
      | "CLICKTHROUGH_2"
81
      | "IMPRESSION_2"
82
      | "TOTAL_CLICKTHROUGH"
83
      | "TOTAL_IMPRESSION"
84
      | "ADVERTISER_NAME"
85
      | "SPEND_ORDER_LINE_PAID_TYPE"[];
86
  },
87
) {
88
  const url = new URL(
89
    `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/mmm_reports`,
90
  );
91

92
  const response = await fetch(url, {
93
    method: "POST",
94
    headers: {
95
      "Content-Type": "application/json",
96
      Authorization: "Bearer " + auth.token,
97
    },
98
    body: JSON.stringify(body),
99
  });
100
  if (!response.ok) {
101
    const text = await response.text();
102
    throw new Error(`${response.status} ${text}`);
103
  }
104
  return await response.json();
105
}
106