0

Search

by
Published Oct 17, 2025

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.

Script yelp Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Yelp = {
3
  apiKey: string;
4
};
5
/**
6
 * Search
7
 * This endpoint returns up to 240 businesses with some basic information based on the provided search criteria.
8

9
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.
10

11
**Note:** The API does not return businesses without any reviews.
12

13
 */
14
export async function main(
15
  auth: Yelp,
16
  location: string | undefined,
17
  latitude: string | undefined,
18
  longitude: string | undefined,
19
  term: string | undefined,
20
  radius: string | undefined,
21
  categories: string | undefined,
22
  locale: string | undefined,
23
  price: string | undefined,
24
  open_now: string | undefined,
25
  open_at: string | undefined,
26
  attributes: string | undefined,
27
  sort_by: "best_match" | "rating" | "review_count" | "distance" | undefined,
28
  device_platform: "android" | "ios" | "mobile-generic" | undefined,
29
  reservation_date: string | undefined,
30
  reservation_time: string | undefined,
31
  reservation_covers: string | undefined,
32
  matches_party_size_param: string | undefined,
33
  limit: string | undefined,
34
  offset: string | undefined,
35
) {
36
  const url = new URL(`https://api.yelp.com/v3/businesses/search`);
37
  for (const [k, v] of [
38
    ["location", location],
39
    ["latitude", latitude],
40
    ["longitude", longitude],
41
    ["term", term],
42
    ["radius", radius],
43
    ["categories", categories],
44
    ["locale", locale],
45
    ["price", price],
46
    ["open_now", open_now],
47
    ["open_at", open_at],
48
    ["attributes", attributes],
49
    ["sort_by", sort_by],
50
    ["device_platform", device_platform],
51
    ["reservation_date", reservation_date],
52
    ["reservation_time", reservation_time],
53
    ["reservation_covers", reservation_covers],
54
    ["matches_party_size_param", matches_party_size_param],
55
    ["limit", limit],
56
    ["offset", offset],
57
  ]) {
58
    if (v !== undefined && v !== "" && k !== undefined) {
59
      url.searchParams.append(k, v);
60
    }
61
  }
62
  const response = await fetch(url, {
63
    method: "GET",
64
    headers: {
65
      Authorization: "Bearer " + auth.apiKey,
66
    },
67
    body: undefined,
68
  });
69
  if (!response.ok) {
70
    const text = await response.text();
71
    throw new Error(`${response.status} ${text}`);
72
  }
73
  return await response.json();
74
}
75