Hourly history with WeatherKit REST API

Has anyone figured out the correct incantation of request parameters to get historic hourly weather conditions from WeatherKit? I've tried every combo of hourlyStart, dailyStart, currentAsOf, etc with past dates and it seems like the oldest it will go back to is midnight for today. I would like to get the last 24 hours of conditions.

Post not yet marked as solved Up vote post of John_s25 Down vote post of John_s25
4.3k views

Replies

Ditto! It respects dailyEnd, but not dailyStart. This query will yield an empty array. Removing dailyEnd will return 10 days of June.

https://weatherkit.apple.com/api/v1/weather/en/41.029/-74.642
?dataSets=forecastDaily
&currentAsOf=2022-01-01T00:00:00Z
&dailyStart=2022-01-01T00:00:00Z
&dailyEnd=2022-01-07T00:00:00Z
&timezone=Americas/Los_Angeles
&countryCode=US

It's probably forthcoming later this summer, but filed FB10383199.

  • Did you ever got an answer to this? I am running into the same issue now so I assume this is not fixed yet. Basically any combinations of dailyStart and dailyEnd are always returning 10 days forecast from the current date. Do you have any idea of when this historical data will be available?

    Thanks!

  • Historical data is currently available back to Aug 1, 2021. Requests can cover any time period of up to 10 days from that date until 10 days from current.

  • @ Frameworks Engineer: Please also bring back earlier dates. Many great app ideas won't work otherwise.

Yeah - we are having the same problems. Can get current weather only but are much more interested in historical.

Lucky you! :) I cannot even get currentWeather. Constantly receiving 401 response.

Same problem here, no way to get the historical data, even though this is advertised. I'm using darksky.net now, which Apple has acquired. Need to port my code to the WeatherKit, and I thought it would be easier with all being on the Apple platform. However, it has has given a lot of headaches so far to try and get everything to work.. :(

Thank you all for the reports. This is a known issue that will be addressed soon.

  • great! love it when you respond directly to threads like this :)

Add a Comment

With the Darksky API, it was possible to get hourly historical weather data of 50 years back. I am struggling with getting the same from the Weatherkit API. Is there an example call that provide e.g. the historical hourly weather data on a specific location, and a date of e.g. 20 years back?

  • Historical weather has been problematic, particularly with daily historical requests for earlier this year, say January 1, 2022. Daily historical weather for days between September and December 2021 have been somewhat reliable. Also, using Time Machine with Carrot Weather and Apple as the weather source led to flakey results. For example, sometimes the hourly results display but not the daily. Just now I checked Carrot Weather again going to the year 2000. Both hourly and daily were retrieved!

  • Historical data is available back to Aug 1, 2021. Requests for earlier dates will not return data.

  • @Frameworks Engineer Will you be able to get earlier data in the future? Dark Sky had this.

With the Swift API (not REST) I'm still finding it to be hit or miss. Here's a look ...

// Historical daily request let forecast: Forecast<WeatherKit.DayWeather> = try await weatherService.weather(for: location, including: .daily(startDate: november24-2021, endDate: november25-2021))

Yes it is still not working even though iOS 16 has been released in the meantime. Not good :(

request like this can get historic hourly weather conditions, but it's not accurate in my area:

GET /api/v1/weather/zh-CN/28.212151/112.955606?countryCode=CN&timeZone=Asia%2FShanghai&dataSets=forecastHourly&hourlyStart=2022-12-15T23%3A46%3A03Z&hourlyEnd=2022-12-17T23%3A46%3A03Z

Attempting to get a actual weather for previous day (e.g. earlier today) I'm getting a status of 400, error: "Bad Request"

Not sure what I'm doing wrong as I'm using forecastHourly in a GET URL as follows:

'https://weatherkit.apple.com/api/v1/weather/en/37.873377/-122.046918?dataSets=forecastHourly&hourlyStart=2023-02-20T17:00:00+00:00'

Maybe I need to encode the hourly start parameter? [tried that to no avail]

Don't really want to have to pass country code as these items are all over the world. I'm hoping that the lat/lon will be sufficient.

I've also attempted to truncate to the hour even vs using the actual datetime stamp [as shown above].

Any suggestions?

Getting a hourly forecast works fine as I'm not sending any parameters so it's not the JWT logic or anything like that...

Thanks,

this works for me. note that you need to update with your token: curl -v -H "Authorization: Bearer {YOUR_TOKEN_HERE}" "https://weatherkit.apple.com/api/v1/weather/en/35.0/-80.0?dataSets=forecastHourly&currentAsOf=2022-01-01T00:00:00Z&hourlyStart=2022-01-01T00:00:00Z&hourlyEnd=2022-01-07T00:00:00Z&timezone=America/New_York&countryCode=US"

the token can be created with python:

import jwt
import datetime

TEAM_ID = 'TTTTTTTTTT' #replace with your team_id from the apple developers site, keep in quotes
KEY_ID = 'KKKKKKKKKK'  #replace with key_id from the apple developers site
APP_ID = 'com.MyVeryOwnURL.WetterAPI' #invent this with your own domain in reverse
file_path = f'./AuthKey_{KEY_ID}.pem' # use full path to the key you download from Apple Developer Site. Note, I converted my .p8 file to .pem using `openssl pkcs8 -nocrypt -in AuthKey_KKKKKKKKKK.p8 -out AuthKey_KKKKKKKKKK.pem`

header = {
  "alg": "ES256",
  "kid": KEY_ID,
  "id": f"{TEAM_ID}.{APP_ID}"
}

current_time = datetime.datetime.utcnow()
expiration_time = current_time + datetime.timedelta(minutes=19)

payload = {
  "iss": TEAM_ID,
  "iat": int(current_time.timestamp()),
  "exp": int(expiration_time.timestamp()),
  "sub": APP_ID
}

with open(file_path, 'r') as file:
  private_key = file.read()


coordinates= '35.0,-80.0'
token = jwt.encode(payload, private_key, algorithm='ES256', headers=header)

# Create the curl command
curl_command = f'curl -v -H "Authorization: Bearer {token}" "https://weatherkit.apple.com/api/v1/weather/en/35.0/-80.0?dataSets=forecastHourly&currentAsOf=2022-01-01T00:00:00Z&hourlyStart=2022-01-01T00:00:00Z&hourlyEnd=2022-01-07T00:00:00Z&timezone=America/New_York&countryCode=US"

print(curl_command)

After that's done, run it in the terminal. it'll give you your the line you need to copy and explicitly paste to execute on the terminal.

good luck!