Tomorrow.io's Resilience Platform is Here. Learn More.

X

Where Can I Find Historical Weather Data?

Using a reliable weather API makes the process of getting historical weather data a breeze.

Filip Dimkovski
By Filip Dimkovski
Joel Taylor editor profile picture
Edited by Joel Taylor

Updated April 19, 2024.

A person holding a cell phone in their hand reading weather data

Historical weather data has proven to be critical across various domains, including climate research, agriculture, and urban planning. This trove of information allows businesses and individuals to decipher patterns, predict future climate events, and make informed decisions that safeguard communities and ecosystems. Detailed insights from the past can equip us with the knowledge to adapt to ever-changing climate conditions and enhance resilience against natural disasters.



Using a Historical Weather Data API

To use a historical weather API, you should choose a reliable weather API provider such as Tomorrow.io. Your first step should be visiting the sign-up page and registering an account. The registration process requires you to fill out a few forms, and you should be done with it within a few minutes.

Once you've registered and have an API key, you can visit the Tomorrow.io documentation to learn about the historical weather API. Simply put, the API allows you to query weather conditions by specifying the locations, such as the response includes a historical timeline.

» Need more help? Here's how to fetch your weather API in JavaScript

Creating the Request in JavaScript

To run your API request, you must first create a JavaScript file—let's call it "historical.js"—and then paste the following code snippet:

const options = {
    method: 'POST',
    headers: {
      accept: 'application/json',
      'Accept-Encoding': 'gzip',
      'content-type': 'application/json'
    },
    body: JSON.stringify({
      location: 'Paris',
      fields: ['temperature'],
      timesteps: ['1d'],
      startTime: '2019-03-20T14:09:50Z',
      endTime: '2019-03-21T14:09:50Z',
      units: 'metric'
    })
  };
  
  fetch('https://api.tomorrow.io/v4/historical?apikey=YOUR_API_KEY', options)
    .then(response => response.json())
    .then(response => console.log(JSON.stringify(response, null, 2)))
    .catch(err => console.error(err));

In the code snippet above, we're making a POST request to the Tomorrow.io API to retrieve historical temperature data for Paris, France, fetching data for a 24-hour period and a daily time step "1d". Also, to make sure that our response is destructured correctly, we log it into the console using a "JSON.stringify()" function.

Please note that "YOUR_API_KEY" needs to be replaced with a valid API key from Tomorrow.io to execute the request successfully.

Reviewing the Response

After successfully executing the POST request to Tomorrow.io's historical weather API, let's take a look at the response received to extract valuable insights:

{
  "data": {
    "timelines": [
      {
        "timestep": "1d",
        "endTime": "2019-03-21T00:00:00Z",
        "startTime": "2019-03-20T00:00:00Z",
        "intervals": [
          {
            "startTime": "2019-03-20T00:00:00Z",
            "values": {
              "temperature": 12.31
            }
          },
          {
            "startTime": "2019-03-21T00:00:00Z",
            "values": {
              "temperature": 15
            }
          }
        ]
      }
    ]
  }
}

As we can see, the response above historical temperature data for Paris over a two-day period, on March 20 and March 21, 2019. The data is organized into daily intervals with a "1d" time step, and a response that captures the daily temperature variation from 12.31°C to 15°C.

» Learn to get historical weather data by zip code

Get Historical Weather Data With Tomorrow.io

Weather APIs like Tomorrow.io make historical weather data significantly more accessible. By providing detailed, accurate historical weather information, these APIs are indispensable tools for researchers, planners, and anyone needing past weather records.