Edits history of script submission #11207 for ' Create a request for a Marketing Mix Modeling (MMM) report (pinterest)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Pinterest = {
      token: string;
    };
    /**
     * Create a request for a Marketing Mix Modeling (MMM) report
     * 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.
     */
    export async function main(
      auth: Pinterest,
      ad_account_id: string,
      body: {
        countries?:
          | "US"
          | "GB"
          | "CA"
          | "IE"
          | "AU"
          | "NZ"
          | "FR"
          | "SE"
          | "IL"
          | "DE"
          | "AT"
          | "IT"
          | "ES"
          | "NL"
          | "BE"
          | "PT"
          | "CH"
          | "HK"
          | "JP"
          | "KR"
          | "SG"
          | "NO"
          | "DK"
          | "FI"
          | "CY"
          | "LU"
          | "MT"
          | "PL"
          | "RO"
          | "HU"
          | "CZ"
          | "GR"
          | "SK"
          | "BR"
          | "MX"
          | "AR"
          | "CL"
          | "CO"[];
      } & {
        report_name: string;
        start_date: string;
        end_date: string;
        granularity: "DAY" | "WEEK";
        level: "CAMPAIGN_TARGETING" | "AD_GROUP_TARGETING";
        targeting_types:
          | "APPTYPE"
          | "COUNTRY"
          | "CREATIVE_TYPE"
          | "GENDER"
          | "LOCATION"[];
        columns:
          | "SPEND_IN_DOLLAR"
          | "SPEND_IN_MICRO_DOLLAR"
          | "ECPC_IN_DOLLAR"
          | "ECTR"
          | "CAMPAIGN_NAME"
          | "TOTAL_ENGAGEMENT"
          | "EENGAGEMENT_RATE"
          | "ECPM_IN_DOLLAR"
          | "CAMPAIGN_ID"
          | "ADVERTISER_ID"
          | "AD_GROUP_ID"
          | "AD_GROUP_NAME"
          | "CLICKTHROUGH_1"
          | "IMPRESSION_1"
          | "CLICKTHROUGH_2"
          | "IMPRESSION_2"
          | "TOTAL_CLICKTHROUGH"
          | "TOTAL_IMPRESSION"
          | "ADVERTISER_NAME"
          | "SPEND_ORDER_LINE_PAID_TYPE"[];
      },
    ) {
      const url = new URL(
        `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/mmm_reports`,
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 536 days ago