Edits history of script submission #21057 for ' Reviews (yelp)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Yelp = {
      apiKey: string;
    };
    /**
     * Reviews
     * This endpoint returns up to three review excerpts for a given business ordered by Yelp's default sort order.
    
    **Note:** at this time, the API does not return businesses without any reviews.
    
    To use this endpoint, make the GET request to the following URL with the ID of the business you want to get reviews for.
    Normally, you'll get the Business ID from /v3/businesses/search,
    /v3/businesses/search/phone, /v3/transactions/{transaction_type}/search or
    /v3/autocomplete.
    
     */
    export async function main(
      auth: Yelp,
      business_id_or_alias: string,
      locale: string | undefined,
      offset: string | undefined,
      limit: string | undefined,
      sort_by: "yelp_sort" | undefined,
    ) {
      const url = new URL(
        `https://api.yelp.com/v3/businesses/${business_id_or_alias}/reviews`,
      );
      for (const [k, v] of [
        ["locale", locale],
        ["offset", offset],
        ["limit", limit],
        ["sort_by", sort_by],
      ]) {
        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