Edits history of script submission #11233 for ' Create product group promotions (pinterest)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Pinterest = {
      token: string;
    };
    /**
     * Create product group promotions
     * Add one or more product groups from your catalog to an existing ad group. (Product groups added to an ad group are a 'product group promotion.')
     */
    export async function main(
      auth: Pinterest,
      ad_account_id: string,
      body: {
        ad_group_id: string;
        product_group_promotion: {
          id?: string;
          ad_group_id?: string;
          bid_in_micro_currency?: number;
          included?: false | true;
          definition?: string;
          relative_definition?: string;
          parent_id?: string;
          slideshow_collections_title?: string;
          slideshow_collections_description?: string;
          is_mdl?: false | true;
          status?: "ACTIVE" | "PAUSED" | "ARCHIVED" | "DRAFT" | "DELETED_DRAFT";
          tracking_url?: string;
          catalog_product_group_id?: string;
          catalog_product_group_name?: string;
          collections_hero_pin_id?: string;
          collections_hero_destination_url?: string;
          grid_click_type?: "CLOSEUP" | "DIRECT_TO_DESTINATION";
        } & {
          creative_type?:
            | "REGULAR"
            | "VIDEO"
            | "SHOPPING"
            | "CAROUSEL"
            | "MAX_VIDEO"
            | "SHOP_THE_PIN"
            | "COLLECTION"
            | "IDEA"
            | "SHOWCASE"
            | "QUIZ";
        }[];
      },
    ) {
      const url = new URL(
        `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/product_group_promotions`,
      );
    
      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