//native
type Yelp = {
apiKey: string;
};
/**
* Business Insights
* Returns Business Insights information for the provided businesses.
This endpoint is part of Yelp Fusion Insights, visit Yelp Fusion Insights to learn more.
*/
export async function main(
auth: Yelp,
business_ids: string | undefined,
date_range_start: string | undefined,
date_range_end: string | undefined,
) {
const url = new URL(`https://api.yelp.com/v3/businesses/insights`);
for (const [k, v] of [
["business_ids", business_ids],
["date_range_start", date_range_start],
["date_range_end", date_range_end],
]) {
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