//native
type Yelp = {
apiKey: string;
};
/**
* Phone Search
* This endpoint returns a list of businesses based on the provided phone number. It is possible for more than one business to have the same phone number (for example, chain stores with the same +1 800 phone number).
Note: at this time, the API does not return businesses without any reviews.
*/
export async function main(
auth: Yelp,
phone: string | undefined,
locale: string | undefined,
) {
const url = new URL(`https://api.yelp.com/v3/businesses/search/phone`);
for (const [k, v] of [
["phone", phone],
["locale", locale],
]) {
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