Edits history of script submission #11274 for ' Get audience sizing (pinterest)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Pinterest = {
      token: string;
    };
    /**
     * Get audience sizing
     * Get potential audience size for an ad group with given targeting criteria. 
    Potential audience size estimates the number of people you may be able to reach per month with your campaign. 
    It is based on historical advertising data and the targeting criteria you select.
    It does not guarantee results or take into account factors such as bid, budget, schedule, seasonality or product experiments.
     */
    export async function main(
      auth: Pinterest,
      ad_account_id: string,
      body: {
        auto_targeting_enabled?: false | true;
        placement_group?: "ALL" | "SEARCH" | "BROWSE" | "OTHER";
        creative_types?:
          | "REGULAR"
          | "VIDEO"
          | "SHOPPING"
          | "CAROUSEL"
          | "MAX_VIDEO"
          | "SHOP_THE_PIN"
          | "COLLECTION"
          | "IDEA"[];
        targeting_spec?: {
          AGE_BUCKET?:
            | "18-24"
            | "21+"
            | "25-34"
            | "35-44"
            | "45-49"
            | "50-54"
            | "55-64"
            | "65+"[];
          APPTYPE?:
            | "android_mobile"
            | "android_tablet"
            | "ipad"
            | "iphone"
            | "web"
            | "web_mobile"[];
          AUDIENCE_EXCLUDE?: string[];
          AUDIENCE_INCLUDE?: string[];
          GENDER?: "unknown" | "male" | "female"[];
          GEO?: string[];
          INTEREST?: string[];
          LOCALE?: string[];
          LOCATION?: string[];
          SHOPPING_RETARGETING?: {
            lookback_window?: number;
            tag_types?: number[];
            exclusion_window?: number;
          }[];
          TARGETING_STRATEGY?:
            | "CHOOSE_YOUR_OWN"
            | "FIND_NEW_CUSTOMERS"
            | "RECONNECT_WITH_USERS"[];
        };
        product_group_ids?: string[];
        keywords?: {
          match_type:
            | "BROAD"
            | "PHRASE"
            | "EXACT"
            | "EXACT_NEGATIVE"
            | "PHRASE_NEGATIVE";
          value: string;
        }[];
      },
    ) {
      const url = new URL(
        `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/ad_groups/audience_sizing`,
      );
    
      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 537 days ago