Edits history of script submission #21059 for ' Search (yelp)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Yelp = {
      apiKey: string;
    };
    /**
     * Search
     * This endpoint returns up to 240 businesses with some basic information based on the provided search criteria.
    
    Explore our new Fusion AI API for conversational search experiences. Try it for free in our playground and see real-time conversational responses in action.
    
    **Note:** The API does not return businesses without any reviews.
    
     */
    export async function main(
      auth: Yelp,
      location: string | undefined,
      latitude: string | undefined,
      longitude: string | undefined,
      term: string | undefined,
      radius: string | undefined,
      categories: string | undefined,
      locale: string | undefined,
      price: string | undefined,
      open_now: string | undefined,
      open_at: string | undefined,
      attributes: string | undefined,
      sort_by: "best_match" | "rating" | "review_count" | "distance" | undefined,
      device_platform: "android" | "ios" | "mobile-generic" | undefined,
      reservation_date: string | undefined,
      reservation_time: string | undefined,
      reservation_covers: string | undefined,
      matches_party_size_param: string | undefined,
      limit: string | undefined,
      offset: string | undefined,
    ) {
      const url = new URL(`https://api.yelp.com/v3/businesses/search`);
      for (const [k, v] of [
        ["location", location],
        ["latitude", latitude],
        ["longitude", longitude],
        ["term", term],
        ["radius", radius],
        ["categories", categories],
        ["locale", locale],
        ["price", price],
        ["open_now", open_now],
        ["open_at", open_at],
        ["attributes", attributes],
        ["sort_by", sort_by],
        ["device_platform", device_platform],
        ["reservation_date", reservation_date],
        ["reservation_time", reservation_time],
        ["reservation_covers", reservation_covers],
        ["matches_party_size_param", matches_party_size_param],
        ["limit", limit],
        ["offset", offset],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.apiKey,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago