Query Weather

Learn how to query weather from the API

Weather information is available for all of our geographies as well.

1. Average Air Temperature over the Past Week

Here is an example that queries the average weather over the past week in the New York MSA:

query PAST_WEEK_AVG_TEMP_NY_MSA {
  MSA(where: {MSA_NAME: {_eq: "New York-Newark-Jersey City, NY-NJ-PA"}}) {
    MSA_NAME
    weather_aggregate(order_by: {DATE: desc}, limit: 7) {
      aggregate {
        avg {
          AIR_TEMPERATURE_F
        }
      }
    }
  }
}

Output:

{
  "data": {
    "MSA": [
      {
        "MSA_NAME": "New York-Newark-Jersey City, NY-NJ-PA",
        "weather_aggregate": {
          "aggregate": {
            "avg": {
              "AIR_TEMPERATURE_F": 49.33571428571429
            }
          }
        }
      }
    ]
  }
}

2. 3 Coldest Cities in the Past Year

Here is an example that queries the three coldest cities over the past year by their average temperature:

query THREE_COLDEST_CITIES {
  CITY(order_by: {weather_aggregate: {avg: {AIR_TEMPERATURE_F: asc}}}, limit: 3) {
    CITY_NAME
    weather_aggregate(order_by: {DATE: desc}, limit: 365) {
      aggregate {
        avg {
          AIR_TEMPERATURE_F
        }
      }
    }
  }
}

Output:

{
  "data": {
    "CITY": [
      {
        "CITY_NAME": "Brook Forest",
        "weather_aggregate": {
          "aggregate": {
            "avg": {
              "AIR_TEMPERATURE_F": 37.226607142857155
            }
          }
        }
      },
      {
        "CITY_NAME": "Black Hawk",
        "weather_aggregate": {
          "aggregate": {
            "avg": {
              "AIR_TEMPERATURE_F": 37.226607142857155
            }
          }
        }
      },
      {
        "CITY_NAME": "Idaho Springs",
        "weather_aggregate": {
          "aggregate": {
            "avg": {
              "AIR_TEMPERATURE_F": 37.226607142857155
            }
          }
        }
      }
    ]
  }
}

What’s Next

You can view our weather objects for a list of all weather variables available in the API.