I'm trying to create multiple JSON objects using an external call out to FourSquare API with different query parameters, but my code keeps returning as a successful response code with no readable results. Here is the code I'm trying to use:
async function getPlaces(query, lat, lon, clientID, clientSecret, versionDate) {
const URL = `https://api.foursquare.com/v2/venues/search?client_id=${clientID}&v=${versionDate}&ll=${lat},${lon}&intent=browse&radius=10000&query=${query}&limit=10&client_secret=${clientSecret}`;
const response = await fetch(URL).catch(e => { console.log(e) });
const data = await response.json().catch(e => { console.log(e) });
return data;
}
When I call this function to create a JSON object like so
const beachData = getPlaces("beaches", lat, lon, clientID, clientSecret, versionDate);
It then returns as this:
Promise { <pending> }
I tried this with the same result
const beachData = getPlaces("beaches", lat, lon, fourSquareClientID, fourSquareClientSecret, versionDate).then(({ beachData }) => { beachData; });
Any guidance on what i'm doing wrong would be HUGELY appreciated. If I'm not totally off the mark I'd like to be able to call on this function a few times and get some JSON objects back I can later combine for the response back to the front end. Thanks!
fetch()yet not know that you need to await the promise returning functiongetPlaces()