0

Business Insights

by
Published Oct 17, 2025

Returns Business Insights information for the provided businesses. This endpoint is part of Yelp Fusion Insights, visit Yelp Fusion Insights to learn more.

Script yelp Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Yelp = {
3
  apiKey: string;
4
};
5
/**
6
 * Business Insights
7
 * Returns Business Insights information for the provided businesses.
8
This endpoint is part of Yelp Fusion Insights, visit Yelp Fusion Insights to learn more.
9

10
 */
11
export async function main(
12
  auth: Yelp,
13
  business_ids: string | undefined,
14
  date_range_start: string | undefined,
15
  date_range_end: string | undefined,
16
) {
17
  const url = new URL(`https://api.yelp.com/v3/businesses/insights`);
18
  for (const [k, v] of [
19
    ["business_ids", business_ids],
20
    ["date_range_start", date_range_start],
21
    ["date_range_end", date_range_end],
22
  ]) {
23
    if (v !== undefined && v !== "" && k !== undefined) {
24
      url.searchParams.append(k, v);
25
    }
26
  }
27
  const response = await fetch(url, {
28
    method: "GET",
29
    headers: {
30
      Authorization: "Bearer " + auth.apiKey,
31
    },
32
    body: undefined,
33
  });
34
  if (!response.ok) {
35
    const text = await response.text();
36
    throw new Error(`${response.status} ${text}`);
37
  }
38
  return await response.json();
39
}
40