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!
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.