JSON REQUEST FAILURE

Tagged:

Currently contains 1 post

Avatar

September 19, 2019 12:24

objevtesumavu

Hello,

I am failing on receiving a response in JSON. Please, could you help?

I can receive a JSON response but as I change the language, JSON response is not working.


XML Format for the Czech language: http://api.weatherunlocked.com/api/forecast/49.086590,13.481500?lang=cs&app_id=c*****&app_key=****

JSON Format for English – working: http://api.weatherunlocked.com/api/trigger/49.086590,13.481500/forecast%20tomorrow%20temperature%20gt%2016%20include7dayforecast?app_id=*******&app_key=2*****

How should we change the request in JSON to get the different language?
This one is not working…
http://api.weatherunlocked.com/api/trigger/49.086590,13.481500/forecast%20tomorrow%20temperature%20gt%2016%20include7dayforecast?lang=cs&app_id=*********&app_key=*******

const getCurrentWeatherJSON = (data) => {
return {
set_attributes: {
dayFirst: data.ForecastWeather.Days0.date,
tempFirst: data.ForecastWeather.Days0.temp_max_c,
daySecond: data.ForecastWeather.Days1.date,
tempSecond: data.ForecastWeather.Days1.temp_max_c,
dayThird: data.ForecastWeather.Days2.date,
tempThird: data.ForecastWeather.Days2.temp_max_c,
dayFourth: data.ForecastWeather.Days3.date,
tempFourth: data.ForecastWeather.Days3.temp_max_c,
dayFifth: data.ForecastWeather.Days4.date,
tempFifth: data.ForecastWeather.Days4.temp_max_c,
daySixth: data.ForecastWeather.Days5.date,
tempSixth: data.ForecastWeather.Days5.temp_max_c,
daySeventh: data.ForecastWeather.Days6.date,
tempSeventh: data.ForecastWeather.Days6.temp_max_c
},
}
};
app.get(‘/weather’, (request, response) => {
const latitude = request.query.latitude;
const longitude = request.query.longitude;
const APP_ID = process.env.WEATHER_APP_ID;
const APP_KEY = process.env.WEATHER_APP_KEY;
const weatherUrl = `http://api.weatherunlocked.com/api/trigger/49.086590,13.481500/forecast%20tomorrow%20temperature%20gt%2016%20include7dayforecast?app_id=***********&app_key=************`;
const requestOptions = {
uri: weatherUrl,
json: true
};
requestPromise(requestOptions)
.then((data) => {
const responseData = getCurrentWeatherJSON(data);
response.json(responseData);
})
.catch((error) => {
console.log(error.message);
response.json({
messages:[{text: ‘Někde se stala chyba.’}]
});
});
});

Reply to thread
  1. If you're human, leave this field empty.