Edits history of script submission #21054 for ' Request Daily Report (yelp)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Yelp = {
      apiKey: string;
    };
    /**
     * Request Daily Report
     * Requests a report containing daily business/advertiser metrics for a specified list of businesses over a date range. Daily metrics can be requested up to 89 days ago.
    
    Use [get_daily_reports_v3](https://docs.developer.yelp.com/reference/get_daily_reports_v3) to poll for report completion and retrieve the report.
    
     */
    export async function main(
      auth: Yelp,
      body: {
        start: string;
        end: string;
        ids: string[];
        metrics:
          | "num_total_page_views"
          | "num_calls"
          | "num_directions_and_map_views"
          | "url_clicks"
          | "num_check_ins"
          | "num_user_photos"
          | "num_bookmarks"
          | "num_desktop_cta_clicks"
          | "num_mobile_cta_clicks"
          | "num_messages_to_business"
          | "num_mobile_page_views"
          | "num_desktop_search_appearances"
          | "num_mobile_search_appearances"
          | "num_desktop_page_views"
          | "tracking_calls"
          | "deals_sold"
          | "online_orders"
          | "online_bookings"
          | "check_in_offer_redemptions"
          | "collection_item_added"
          | "rapc_initiated"
          | "waitlist_visit_created"
          | "median_response_time_in_sec"
          | "reply_rate"
          | "organic_biz_page_views"
          | "organic_biz_page_views_percentage"
          | "rating"
          | "reviews"
          | "total_leads"
          | "billed_impressions"
          | "billed_clicks"
          | "ad_cost"
          | "ad_driven_bookmarks"
          | "ad_driven_calls"
          | "ad_driven_cta_clicks"
          | "ad_driven_check_ins"
          | "ad_driven_deals_sold"
          | "ad_driven_directions_and_map_views"
          | "ad_driven_messages_to_business"
          | "ad_driven_user_photos"
          | "ad_driven_online_reservations"
          | "ad_driven_url_clicks"
          | "ad_click_through_rate"
          | "average_cost_per_click"
          | "billable_ad_clicks"
          | "billable_ad_impressions"
          | "ad_driven_biz_page_views"
          | "ad_driven_calls_tracked"
          | "ad_driven_rapc_initiated"
          | "ad_driven_waitlist_visit_created"
          | "ad_driven_total_leads"
          | "ad_driven_platform_purchase_made"
          | "ad_driven_biz_page_views_percentage"[];
      },
    ) {
      const url = new URL(`https://api.yelp.com/v3/reporting//businesses/daily`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.apiKey,
        },
        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 235 days ago