Edits history of script submission #11216 for ' Create audience (pinterest)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Pinterest = {
      token: string;
    };
    /**
     * Create audience
     * Create an audience you can use in targeting for specific ad groups. Targeting combines customer information with
    the ways users interact with Pinterest to help you reach specific groups of users; you can include or exclude
    specific audience_ids when you create an ad group. 
    For more, see Audience targeting.
     */
    export async function main(
      auth: Pinterest,
      ad_account_id: string,
      body: {
        ad_account_id?: string;
        name?: string;
        rule?: {
          country?: string;
          customer_list_id?: string;
          engagement_domain?: string[];
          engagement_type?: string;
          event?: string;
          event_data?: {
            currency?:
              | "UNK"
              | "USD"
              | "GBP"
              | "CAD"
              | "EUR"
              | "AUD"
              | "NZD"
              | "SEK"
              | "ILS"
              | "CHF"
              | "HKD"
              | "JPY"
              | "SGD"
              | "KRW"
              | "NOK"
              | "DKK"
              | "PLN"
              | "RON"
              | "HUF"
              | "CZK"
              | "BRL"
              | "MXN"
              | "ARS"
              | "CLP"
              | "COP"
              | "INR"
              | "TRY";
            lead_type?: string;
            line_items?: {
              product_brand?: string;
              product_category?: string;
              product_id?: number;
              product_name?: string;
              product_price?: string;
              product_quantity?: number;
              product_variant?: string;
              product_variant_id?: string;
            };
            order_id?: string;
            order_quantity?: number;
            page_name?: string;
            promo_code?: string;
            property?: string;
            search_query?: string;
            value?: string;
            video_title?: string;
          };
          percentage?: number;
          pin_id?: string[];
          prefill?: false | true;
          retention_days?: number;
          seed_id?: string[];
          url?: string[];
          visitor_source_id?: string;
          event_source?: {};
          ingestion_source?: {};
          engager_type?: number;
          campaign_id?: string[];
          ad_id?: string[];
          objective_type?:
            | "AWARENESS"
            | "CONSIDERATION"
            | "VIDEO_VIEW"
            | "WEB_CONVERSION"
            | "CATALOG_SALES"
            | "WEB_SESSIONS"
            | "VIDEO_COMPLETION"[];
          ad_account_id?: string;
        };
      } & {
        description?: string;
        audience_type:
          | ("CUSTOMER_LIST" & {})
          | ("VISITOR" & {})
          | ("ENGAGEMENT" & {})
          | ("ACTALIKE" & {})
          | ("PERSONA" & {});
      },
    ) {
      const url = new URL(
        `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/audiences`,
      );
    
      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