Edits history of script submission #11392 for ' Update campaigns (pinterest)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Pinterest = {
      token: string;
    };
    /**
     * Update campaigns
     * Update multiple ad campaigns based on campaign_ids.
     */
    export async function main(
      auth: Pinterest,
      ad_account_id: string,
      body: { id?: string } & {
        ad_account_id?: string;
        name?: string;
        status?: "ACTIVE" | "PAUSED" | "ARCHIVED" | "DRAFT" | "DELETED_DRAFT";
        lifetime_spend_cap?: number;
        daily_spend_cap?: number;
        order_line_id?: string;
        tracking_urls?: {
          impression?: string[];
          click?: string[];
          engagement?: string[];
          buyable_button?: string[];
          audience_verification?: string[];
        };
        start_time?: number;
        end_time?: number;
        is_flexible_daily_budgets?: false | true;
      } & {
        default_ad_group_budget_in_micro_currency?: number;
        is_automated_campaign?: false | true;
      } & {
          is_campaign_budget_optimization?: false | true;
          objective_type?:
            | "AWARENESS"
            | "CONSIDERATION"
            | "VIDEO_VIEW"
            | "WEB_CONVERSION"
            | "CATALOG_SALES"
            | "WEB_SESSIONS"
            | "VIDEO_COMPLETION";
        }[],
    ) {
      const url = new URL(
        `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/campaigns`,
      );
    
      const response = await fetch(url, {
        method: "PATCH",
        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