WeatherKit REST API WeatherAlert data question

I'm trying and failing to find any documentation or example of the structure that the REST API's weather alerts come in. In the app, they returned as an array of alerts, but the REST documentation doesn't make it clear how they will look in the response body.

 { weatherAlerts { 
    ...
    }
}

or

 { weatherAlerts { [
    ...
   ] }
}

I'm hoping a developer or someone who's successfully seen an alert through them can let me know. An example of the JSON object would be truly great. It would save quite a lot of trouble.

Thanks!

Answered by VoyagerSpace in 745866022

Welp, I figured it out.

The answer is that they come in the form of a weatherAlerts {} objects, and within that are alerts.

The object looks like

weatherAlerts: {
    name: 'WeatherAlertCollection',
    metadata: {
      attributionURL: 'https://weatherkit.apple.com/legal-attribution.html',
      expireTime: '2023-02-24T02:11:03Z',
      language: 'en-US',
      latitude: 38.102,
      longitude: -121.523,
      providerName: 'National Weather Service',
      readTime: '2023-02-24T02:06:03Z',
      reportedTime: '2023-02-24T02:06:03Z',
      version: 1
    },
    detailsUrl: 'https://weatherkit.apple.com/alertDetails/index.html?ids=6f7b2352-32f7-5bec-8ac8-ca076081a8a6&lang=en-US&timezone=America/Los_Angeles',
    alerts: [ [Object] ]
  }

And the alerts object looks like this

{
  "name": "WeatherAlertSummary",
  "id": "6f7b2352-32f7-5bec-8ac8-ca076081a8a6",
  "areaId": "caz018",
  "areaName": "Carquinez Strait and Delta",
  "attributionURL": "https://alerts.weather.gov/cap/wwacapget.php?x=CA126637448CAC.WindAdvisory.1266375FF640CA.STONPWSTO.5ff78b05a939c15640f1e82f369abae7",
  "countryCode": "US",
  "description": "Wind Advisory",
  "token": "WIND_ADVISORY",
  "effectiveTime": "2023-02-23T20:35:00Z",
  "expireTime": "2023-02-25T00:00:00Z",
  "issuedTime": "2023-02-23T20:35:00Z",
  "eventEndTime": "2023-02-25T00:00:00Z",
  "detailsUrl": "https://weatherkit.apple.com/alertDetails/index.html?ids=6f7b2352-32f7-5bec-8ac8-ca076081a8a6&lang=en-US&timezone=America/Los_Angeles",
  "phenomenon": "Wind",
  "precedence": 0,
  "severity": "minor",
  "significance": "advisory",
  "source": "National Weather Service",
  "eventSource": "US",
  "urgency": "expected",
  "certainty": "likely",
  "importance": "low",
  "responses": []
}

However, the reason I was having such a hard time finding any alerts in all of my testing is because the country code and timezone query parameters are required in the request URL. That wasn't explained in the docs, as far as I can tell, and that's incredibly disappointing and frustrating. I hope that can be made more obvious for future developers.

Hope this post itself is helpful for anyone stuck.

Accepted Answer

Welp, I figured it out.

The answer is that they come in the form of a weatherAlerts {} objects, and within that are alerts.

The object looks like

weatherAlerts: {
    name: 'WeatherAlertCollection',
    metadata: {
      attributionURL: 'https://weatherkit.apple.com/legal-attribution.html',
      expireTime: '2023-02-24T02:11:03Z',
      language: 'en-US',
      latitude: 38.102,
      longitude: -121.523,
      providerName: 'National Weather Service',
      readTime: '2023-02-24T02:06:03Z',
      reportedTime: '2023-02-24T02:06:03Z',
      version: 1
    },
    detailsUrl: 'https://weatherkit.apple.com/alertDetails/index.html?ids=6f7b2352-32f7-5bec-8ac8-ca076081a8a6&lang=en-US&timezone=America/Los_Angeles',
    alerts: [ [Object] ]
  }

And the alerts object looks like this

{
  "name": "WeatherAlertSummary",
  "id": "6f7b2352-32f7-5bec-8ac8-ca076081a8a6",
  "areaId": "caz018",
  "areaName": "Carquinez Strait and Delta",
  "attributionURL": "https://alerts.weather.gov/cap/wwacapget.php?x=CA126637448CAC.WindAdvisory.1266375FF640CA.STONPWSTO.5ff78b05a939c15640f1e82f369abae7",
  "countryCode": "US",
  "description": "Wind Advisory",
  "token": "WIND_ADVISORY",
  "effectiveTime": "2023-02-23T20:35:00Z",
  "expireTime": "2023-02-25T00:00:00Z",
  "issuedTime": "2023-02-23T20:35:00Z",
  "eventEndTime": "2023-02-25T00:00:00Z",
  "detailsUrl": "https://weatherkit.apple.com/alertDetails/index.html?ids=6f7b2352-32f7-5bec-8ac8-ca076081a8a6&lang=en-US&timezone=America/Los_Angeles",
  "phenomenon": "Wind",
  "precedence": 0,
  "severity": "minor",
  "significance": "advisory",
  "source": "National Weather Service",
  "eventSource": "US",
  "urgency": "expected",
  "certainty": "likely",
  "importance": "low",
  "responses": []
}

However, the reason I was having such a hard time finding any alerts in all of my testing is because the country code and timezone query parameters are required in the request URL. That wasn't explained in the docs, as far as I can tell, and that's incredibly disappointing and frustrating. I hope that can be made more obvious for future developers.

Hope this post itself is helpful for anyone stuck.

@VoyagerSpace... hmm, that's not ideal! The docs do say that countryCode "is necessary for weather alerts" but it doesn't say anything about timezone. Even if the docs were clear, these shouldn't ideally be required anyway from a usability point of view (it requires a couple of extra lookups if timezone and countryCode are not available, e.g. if all you have is a coordinate).

In any case, I still can't get any alerts to show up at all, even when specifying timezone and countryCode. I've tried locations with active alerts on https://www.weather.gov/ and https://www.meteoalarm.org/.

Any other tricks I'm missing? Perhaps the alerts are more limited that what is available elsewhere, and I just haven't found one yet that shows up?

Here's an example of what I'm using now:

URL: https://weatherkit.apple.com/api/v1/weather/en/35.244/-111.269

Query parameters: { dataSets: 'forecastHourly,forecastNextHour,forecastDaily,weatherAlerts', timezone: 'MST', countryCode: 'US' }

I am getting weather alerts as expected. Perhaps use the time zone name instead of the abbreviation? Per docs: "The name of the timezone to use for rolling up weather forecasts into daily forecasts"

WeatherKit REST API WeatherAlert data question
 
 
Q