Edits history of script submission #11235 for ' Create targeting templates (pinterest)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Pinterest = {
      token: string;
    };
    /**
     * Create targeting templates
     * Targeting templates allow advertisers to save a set of targeting details including audience lists,
     keywords & interest, demographics, and placements to use more than once during the campaign creation process.
     Templates can be used to build out basic targeting criteria that you plan to use across campaigns and to reuse
      performance targeting from prior campaigns for new campaigns.
     */
    export async function main(
      auth: Pinterest,
      ad_account_id: string,
      body: {
        name?: string;
        auto_targeting_enabled?: false | true;
        targeting_attributes?: {
          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"[];
        };
        placement_group?: "ALL" | "SEARCH" | "BROWSE" | "OTHER";
        keywords?: {
          match_type?:
            | "BROAD"
            | "PHRASE"
            | "EXACT"
            | "EXACT_NEGATIVE"
            | "PHRASE_NEGATIVE";
          value?: string;
        }[];
        tracking_urls?: {
          impression?: string[];
          click?: string[];
          engagement?: string[];
          buyable_button?: string[];
          audience_verification?: string[];
        };
      } & {
        name: string;
        targeting_attributes: {
          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"[];
        };
      },
    ) {
      const url = new URL(
        `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/targeting_templates`,
      );
    
      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