Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Gabotronix's avatar

Openweather.com API 5 next days forecast issue

Hi everybody, this is my first time using openweather.com API for weather forecasts, I just want to show the following information for the next 5 days:

Min and Max temperature of each day Weather icon Current weather description (Drizzle, Sunny...)

Plain simple, for some reason I'm getting pretty weird results, take a look at the image bellow so you can understand (I THINK that this five results are actually of the same day, different timestamps, look at min/max temp, maybe? instead of the next 5 days...

https://i.imgur.com/QnWR4R5.jpg

This is my code:

async getForecast()
    {
        let url = "https://api.openweathermap.org/data/2.5/forecast";
        let payload = 
        {
            lat: this.$app.globals.origin.lat,
            lon: this.$app.globals.origin.lng,
            units: 'metric',
            APPID: '0feb06072d87320932559f321ca221fb',
            lang:'es',
            cnt:5
        };

        let response = await axios.get(url, { params: payload });
        this.data = response.data.list;
    }

In my view (Vue.js):

<div style="width:auto; height:100%; display:flex; align-items:center;">
                <a  style="width:auto; padding:10; height:100%; display:flex; flex-direction:column; align-items:center; justify-content:space-around;" v-for="(item,index) in data" :key="index">
                    <span class="fs_smaller c_normal">{{ item.main.temp_min }} / {{ item.main.temp_max }}</span>
                    <span class="fs_smaller c_normal">{{ item.weather[0].description }}</span>
                    <img style="width:50px; height:auto;" :src="'https://openweathermap.org/img/w/'+item.weather[0].icon+'.png'">
                </a>
            </div>
0 likes
2 replies
srasch's avatar

This is not completly wrong. You just hit the wrong endpoint.

The cnt parameter gives you the count of data. With this endpoint you get a 5 day forecast with a 3 hour interval per day, which means:

1 day - cnt = 8
2 days - cnt = 16
3 days - cnt = 24
4 days - cnt = 32
5 days - cnt = 40

If you just want to have 1 result per day, you have to subscribe for the daily forcast API. In this case, cnt will be the number of days (bewteen 1 and 16).

Gabotronix's avatar

Yeah but that endpoint is a paid service, is there really no way to get the data I want with my current free endpoint?

Please or to participate in this conversation.