Support Center

Name is required.
Email address is required.
Invalid email address
Answer is required.
Exceeding max length of 5KB

API call not returning JSON

Alan Charles Mar 08, 2019 06:12PM GMT


Hello,

this might be really stupid but I keep getting the following error when trying to make the api call in my React app.

Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0

my api call is relatively simple:

export const fetchWeather = async () => {
const url = `api.openweathermap.org/data/2.5/weather?zip=18847&APPID=${weatherKey}`;

const response = await fetch(url);
console.log(response)
const weatherData = await response.json();
console.log(weatherData)

}

when i try it in postman i get the response I'm looking for :


{
"coord": {
"lon": -75.58,
"lat": 41.96
},
"weather": [
{
"id": 500,
"main": "Rain",
"description": "light rain",
"icon": "10d"
},
{
"id": 600,
"main": "Snow",
"description": "light snow",
"icon": "13d"
}
],
"base": "stations",
"main": {
"temp": 272.3,
"pressure": 957,
"humidity": 46,
"temp_min": 269.26,
"temp_max": 274.82
},

Post Your Public Answer

Your name (required)
Your email address (required)
Answer (required)
9eda11838f597e7a95b6a1c991dcae0a@openweathermap.desk-mail.com
https://cdn.desk.com/
false
desk
Loading
seconds ago
a minute ago
minutes ago
an hour ago
hours ago
a day ago
days ago
about
false
Invalid characters found
/customer/en/portal/articles/autocomplete