dateSet forecastDaily always returning 404 for past 12 hours has been working for months

The URL was working for rmonths and not a "Not Found" error. Just started getting 404s for past 12 hours. Is something broken with weatherkit rest api side? Is there a status link one could check?

Calls to datasets of "currentWeather" are working

https://weatherkit.apple.com/api/v1/weather/en/47.64750/-122.40415?dataSets=forecastDaily&currentAsOf=2023-02-16T20:44:59.209Z&dailyStart=2023-02-16T20:44:59.209Z&dailyEnd=2023-02-26T20:44:59.209Z&timezone=Americas/Los_Angeles&countryCode=US

  response: {
    status: 404,
    statusText: 'Not Found',
    headers: AxiosHeaders {
      server: 'Apple',
      'content-length': '0',
      'x-frame-options': 'SAMEORIGIN',
      'strict-transport-security': 'max-age=31536000; includeSubdomains',
      'x-xss-protection': '1; mode=block',
      'access-control-allow-origin': '*',
      'x-content-type-options': 'nosniff',
      'content-security-policy': "default-src 'self';",
      'x-request-id': '6f5a602a-ee78-43d9-8b28-357facccdacd',
      'x-apple-origin': 'a02b501c-3422-35ef-9768-03404535d1e3',
      date: 'Thu, 16 Feb 2023 20:44:59 GMT',
      'x-cache': 'TCP_MISS from a23-52-133-72.deploy.akamaitechnologies.com (AkamaiGHost/11.0.0-46340752) (-)',
      connection: 'close'
    },
    config: {
      transitional: [Object],
      adapter: [Array],
      transformRequest: [Array],
      transformResponse: [Array],
      timeout: 0,
      xsrfCookieName: 'XSRF-TOKEN',
      xsrfHeaderName: 'X-XSRF-TOKEN',
      maxContentLength: -1,
      maxBodyLength: -1,
      env: [Object],
      validateStatus: [Function: validateStatus],
      headers: [AxiosHeaders],
      method: 'get',
      url: 'https://weatherkit.apple.com/api/v1/weather/en/47.64750/-122.40415?dataSets=forecastDaily&currentAsOf=2023-02-16T20:44:59.209Z&dailyStart=2023-02-16T20:44:59.209Z&dailyEnd=2023-02-26T20:44:59.209Z&timezone=Americas/Los_Angeles&countryCode=US',
      data: undefined
    },

Same here, looks like something broken on their side and I can't find any info on API status.

WeatherKit provides a ten day forecast starting from the beginning of the current day in the specified time zone, and the query parameters you are giving extend into an 11th day. Since WeatherKit cannot satisfy the entire request, it returns HTTP 404.

Rather than keeping track of the exact end time you need--including applying the necessary Daylight Savings Time conversion when appropriate--it may be simpler to just omit the dailyEnd parameter. When that is not specified, WeatherKit determines the correct end point for a 10-day forecast starting at the beginning of the day specified by dailyStart. If dailyStart is in the future and there are fewer than 10 days available, it automatically ends where the available forecast data ends.

Today (12/16/23), I began getting this same 404 error in my code. I also was using code that had been working for the last month or more.

I was requesting forecast data for the date range starting at the current time and going until 10 days in the future from the current time.

When I switched my code to request forecast data from the beginning of the day until ten days from the beginning of the day, the 404 error went away.

So I was experiencing the same error that moscarillo was experiencing, and I was able to fix it by following the advice given by the Apple Frameworks Engineer.

fwiw, here is the code that is working for me now:

            let startOfToday = Calendar.current.startOfDay(for: Date())
            let startDate = Calendar.current.date(byAdding: DateComponents(day: -10), to: startOfToday)!
            let endDate = Calendar.current.date(byAdding: DateComponents(day: 10), to: startOfToday)!

            let current: CurrentWeather
            let futureDaily: Forecast<DayWeather>
            let futureHourly: Forecast<HourWeather>
            let alerts: [WeatherAlert]?

            let historicDaily: any Collection<DayWeather>
            let historicHourly: any Collection<HourWeather>

            (current,
             futureDaily,
             futureHourly,
             alerts) = try await self.weather(for: location,
                                              including: .current,
                                              .daily(startDate: startOfToday, endDate: endDate),
                                              .hourly(startDate: startOfToday, endDate: endDate),
                                              .alerts)

Same here. All of the sudden, the API returns 404.

That did it. Thank you for the quick response and fix!!!

We were also running into this. We wanted the daily weather for just today, so we were doing this:

try await weatherService.weather(for: location, including: .current, .daily(startDate: Date(), endDate: Date()) )

And as of a few days ago, that started giving back errors. I've found, though, that adjusting the endDate forward seems to fix it. At the moment, I'm just advancing it by 86400 seconds and then ignoring the possible data for tomorrow, but there may be a better way to do that.

The API docs aren't particularly clear about what time should be used on the date objects passed to .daily(). Does it need to include the start of the specified day? Noon? I assumed it would give back the weather for any day that was even partially covered by the request, but that appears to no longer be the case.

I'm seeing this when fetching dataSets: "forecastHourly,forecastNextHour" in the REST API.

I've been passing hourlyEnd in the form "2023-03-05T09:35:08.843Z" and it's worked fine until now. But I'm now getting "Request failed with status code 404".

If I remove hourlyEnd completely, the request returns fine, but I then only get 24 hours of data.

Any ideas?

And it doesn't make any difference (same 404 error) if I reduce the hourlyEnd to well within the 10 day limit, and make coincide with the start of the day... i.e. hourlyEnd: "2023-02-27T00:00:00Z" doesn't work either.

At the moment I'm using a ridiculous workaround, which is to request the forecastDaily dataSet even though I don't need it (along with forecastHourly which is what I really need).

This is because I can then leave out hourlyEnd completely and still get the full 10 days of data, in view of the docs:

hourlyEnd (date-time): The time to end the hourly forecast. If this parameter is absent, hourly forecasts run 24 hours or the length of the daily forecast, whichever is longer.

dailyEnd (date-time): The time to end the daily forecast. If this parameter is absent, daily forecasts run for 10 days.

@drmrbrewer Thanks for reporting this. Are you seeing this error when passing only hourlyEnd? An alternative that may work for you would be pass both hourlyStart and hourlyEnd in your request for the hourly forecast instead of just the hourlyEnd.

@Frameworks Engineer thanks for the reply.

Yes I get the error when passing only hourlyEnd and not hourlyStart, which is apparently OK according to the docs:

hourlyStart (date-time): The time to start the hourly forecast. If this parameter is absent, hourly forecasts start on the current hour.

hourlyEnd (date-time): The time to end the hourly forecast. If this parameter is absent, hourly forecasts run 24 hours or the length of the daily forecast, whichever is longer.

I'd just seen this post, which also suggests also passing hourlyStart (even though it's apparently optional), and indeed it does work. Probably a better workaround than asking for forecastDaily (and then just ignoring the return data).

Will this behaviour be fixed (i.e. not being able to pass only hourlyEnd), or at least will the docs be updated?

It would also be useful to have more information about the date-time format... at the moment I'm using ISO format, i.e. in javascript (new Date()).toISOString(), but I can't see from the docs for sure that this is correct (or whether it might break in future if I'm not using exactly the right format).

dateSet forecastDaily always returning 404 for past 12 hours has been working for months
 
 
Q