yelp-fusion
yelp-fusion copied to clipboard
Maximum of 200 businesses returned by /businesses/search
According to the docs, the API should return up to 1000 businesses. However no matter what coordinates I try with, I never seem to get more than 200.
My requests are paged with the maximum limit of 50, my search looks roughly like this:
const MAX_BUSINESSES = 1000;
function requestBusinesses(data, city, authHeader, offset, doneCallback) {
const limitPerRequest = 50;
let url = 'https://api.yelp.com/v3/businesses/search';
const getParams = {
sort_by: 'review_count',
radius: 40000,
limit: limitPerRequest,
latitude: city.Latitude,
longitude: city.Longitude
};
if (offset) {
getParams.offset = offset;
}
url += '?' + queryString.stringify(getParams);
request.get({
url,
headers: {
Authorization: authHeader,
}
}, function(error, response, body) {
body = JSON.parse(body);
const businesses = body.businesses;
if (businesses) {
data.push(...businesses);
offset += businesses.length;
const hasAll = data.length >= MAX_BUSINESSES;
const exhausted = businesses.length < limitPerRequest;
if (!hasAll && !exhausted) {
requestBusinesses(data, city, authHeader, offset, doneCallback);
}
else {
if(exhausted) {
console.log('Stopped collecting businesses, API doesn\'t have any more.');
}
doneCallback();
}
}
});
}
Hey @danfooo, this is a gap in our documentation. Sorting by review_count maxes out at 200, sorting by best_match will give you 1000. We'll update the docs.
Hi @tomelm is sorting by distance maxes out at 200 as well? I have limit set to 50 and returned data always has an empty businesses array after offset>=200. I'm using term, location, limit, offset and sort_by as parameters.
Sorting by rating also appears to max out at 200. Also, the returned "total" value appears incorrect when doing sort_by=rating. It always returns a max value of "40" even when there are actually 200 results. When not using sort_by parameter, the total value is correct.
I've been using the fusion api just fine until recently. Now, everything returns a total of 200. I can't get any request to return more than 200 results.