1 | |
2 | type Yelp = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Business Match |
7 | * This endpoint lets you match business data from other sources against businesses on Yelp, based on provided business information. |
8 | */ |
9 | export async function main( |
10 | auth: Yelp, |
11 | name: string | undefined, |
12 | address1: string | undefined, |
13 | address2: string | undefined, |
14 | address3: string | undefined, |
15 | city: string | undefined, |
16 | state: string | undefined, |
17 | country: string | undefined, |
18 | postal_code: string | undefined, |
19 | latitude: string | undefined, |
20 | longitude: string | undefined, |
21 | phone: string | undefined, |
22 | yelp_business_id: string | undefined, |
23 | limit: string | undefined, |
24 | match_threshold: "none" | "default" | "strict" | undefined, |
25 | ) { |
26 | const url = new URL(`https://api.yelp.com/v3/businesses/matches`); |
27 | for (const [k, v] of [ |
28 | ["name", name], |
29 | ["address1", address1], |
30 | ["address2", address2], |
31 | ["address3", address3], |
32 | ["city", city], |
33 | ["state", state], |
34 | ["country", country], |
35 | ["postal_code", postal_code], |
36 | ["latitude", latitude], |
37 | ["longitude", longitude], |
38 | ["phone", phone], |
39 | ["yelp_business_id", yelp_business_id], |
40 | ["limit", limit], |
41 | ["match_threshold", match_threshold], |
42 | ]) { |
43 | if (v !== undefined && v !== "" && k !== undefined) { |
44 | url.searchParams.append(k, v); |
45 | } |
46 | } |
47 | const response = await fetch(url, { |
48 | method: "GET", |
49 | headers: { |
50 | Authorization: "Bearer " + auth.apiKey, |
51 | }, |
52 | body: undefined, |
53 | }); |
54 | if (!response.ok) { |
55 | const text = await response.text(); |
56 | throw new Error(`${response.status} ${text}`); |
57 | } |
58 | return await response.json(); |
59 | } |
60 |
|