Edits history of script submission #11317 for ' Get product group promotions (pinterest)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Pinterest = {
      token: string;
    };
    /**
     * Get product group promotions
     * List existing product group promotions associated with an ad account.
    
    Include either ad_group_id or product_group_promotion_ids in your request.
    
    Note: ad_group_ids and product_group_promotion_ids are mutually exclusive parameters.
    Only provide one. If multiple options are provided, product_group_promotion_ids takes precedence over ad_group_ids. If none are provided, the endpoint returns an error.
     */
    export async function main(
      auth: Pinterest,
      ad_account_id: string,
      product_group_promotion_ids: string | undefined,
      entity_statuses: string | undefined,
      ad_group_id: string | undefined,
      page_size: string | undefined,
      order: "ASCENDING" | "DESCENDING" | undefined,
      bookmark: string | undefined,
    ) {
      const url = new URL(
        `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/product_group_promotions`,
      );
      for (const [k, v] of [
        ["product_group_promotion_ids", product_group_promotion_ids],
        ["entity_statuses", entity_statuses],
        ["ad_group_id", ad_group_id],
        ["page_size", page_size],
        ["order", order],
        ["bookmark", bookmark],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 536 days ago