Hi @stefisinca3621512529 and @mike7127143742! Based on codecademy’s instructions, your code is correct! However, the version of Foresquare’s API used in this project has since been deprecated. I found this forum post here on codecadmy first and used @wfarat 's response to resolve and understand the issue myself.
TLDR - To fo fix the issue, you need to do two things:
1. Generate an an API key for your project on ForSquare’s developer portal. This is what that should look like:
2. Change the part of your code where you’re making a get request to the ForSquare API to this:
const options = {method: 'GET', headers: {Accept: 'application/json', Authorization: 'API KEY'}};
const urlToFetch = `https://api.foursquare.com/v3/places/search?near=${city}&limit=10`
const response = await fetch(urlToFetch, options)
The longer explanation:
If you were to run and log the error of your fetch code locally (I did this in node), you’ll get something like this error message:
{
meta: {
code: 410,
errorType: 'deprecated',
errorDetail: 'Usage of the V2 Places API has been deprecated for new Projects. Please see our updated documentation for V3 for more details: https://docs.foursquare.com/reference',
requestId: '61cc6f26aacc462cbc8dc579'
},
response: {}
}
In other words, your code would probably have worked if you had registered this Project prior to V2 of the API being deprecated. However, ForSquare now wants you to use their updated API.
The new Version of the API does not map 100% to the older version that the project instructions are based on. There is no longer an “explore” for “venues” endpoint. Instead, the closest thing seems to be “search” for “places”. You can find the details on it here. The new endpoint is https://api.foursquare.com/v3/places/search
. The query params for the url also change slightly. limit
and city
are still needed, but you need to remove the client_id
, client_secret
and v
parameters from the URL.
v
's functionality is not supported from by this endpoint. We remove the other two parameters because this version of the API handles authorization via the Authorization: 'API KEY'
key-value pair that’s nested in the init object, options
. This object is the second argument that we then pass to fetch. You can see mdn’s documentation on fetch for more details on this.
Hope that helped!