Wanderlust - 400Error on step 13

Hello everyone,

I have tried looking up a solution to my issue but couldn’t really find anything… I don’t receive any message on the console if don’t write an ‘Else’ to my response.ok. But once I write the ‘Else’ I am told I have a 400 Error.

const getVenues = async () => {
  const city =  $input.val();
  const urlToFetch = `${url}${city}&limit=10&client_id=${clientId}&client_secret=${clientSecret}&v=20200529`;
    const response = await fetch(urlToFetch);
      const jsonResponse = await response.json();
    } else {
      throw new Error('Request failed!');

Hi there.

Welcome to the forums.

What value have you set for const url please? :slight_smile:

You’re getting an HTTP 400 (Bad Request) error from the Foursquare API. I can’t see anything immediately wrong with the urlToFetch variable, but I can’t see the value of url which you’re interpolating so not 100% sure. :slight_smile:

Here is all the code before getVenues, I tried two sets of API keys for both but still had issues. I removed them in this comment.

// Foursquare API Info
const clientId = '';
const clientSecret = '';
const url = 'https://api.foursquare.com/v2/venues/explore/near=';

// OpenWeather Info
const openWeatherKey = '';
const weatherUrl = 'https://api.openweathermap.org/data/2.5/weather';

// Page Elements
const $input = $('#city');
const $submit = $('#button');
const $destination = $('#destination');
const $container = $('.container');
const $venueDivs = [$("#venue1"), $("#venue2"), $("#venue3"), $("#venue4")];
const $weatherDiv = $("#weather1");
const weekDays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];


I found your issue:

It should be explore?near= not explore/near= :slight_smile:

near is the first parameter of the query string, so should be preceded by the ? to tell the remote server that what follows are the key-value pairs of information. :slight_smile: Without it, your request isn’t correctly formatted which explains the HTTP 400 error.

Easy typo to make, btw. :slight_smile:

1 Like

OMG. Thank you very much :raised_hands:t4:

I will be more aware of query strings moving forwards!

No worries. :slight_smile: