Edits history of script submission #11268 for ' Get advertiser entities in bulk (pinterest)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Pinterest = {
      token: string;
    };
    /**
     * Get advertiser entities in bulk
     * Create an asynchronous report that may include information on campaigns, ad groups, product groups, ads,
    and/or keywords; can filter by campaigns. Though the entities may be active, archived, or paused,
    only active entities will return data.
     */
    export async function main(
      auth: Pinterest,
      ad_account_id: string,
      body: {
        entity_types?:
          | "CAMPAIGN"
          | "AD_GROUP"
          | "PRODUCT_GROUP"
          | "AD"
          | "KEYWORD"[];
        entity_ids?: string[];
        updated_since?: string;
        campaign_filter?: {
          start_time?: string;
          end_time?: string;
          name?: string;
          campaign_status?:
            | "RUNNING"
            | "PAUSED"
            | "NOT_STARTED"
            | "COMPLETED"
            | "ADVERTISER_DISABLED"
            | "ARCHIVED"
            | "DRAFT"
            | "DELETED_DRAFT"[];
          objective_type?:
            | "AWARENESS"
            | "CONSIDERATION"
            | "VIDEO_VIEW"
            | "WEB_CONVERSION"
            | "CATALOG_SALES"
            | "WEB_SESSIONS"
            | "VIDEO_COMPLETION"[];
        };
        output_format?: "CSV" | "JSON";
      },
    ) {
      const url = new URL(
        `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/bulk/download`,
      );
    
      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