WeatherKit REST weather alerts

So, is the weatherAlerts field ever populated? From my (limited experience) it does not populate with current NWS alerts.

Replies

Yes, one can get water alerts issued by the National Weather Service from WeatherKit. All you need to do is to specify weatherAlerts in your dataSets query parameter and include the country parameter indicating which government authority should be issuing the alert.

For example, I can get the currently active alert in San Francisco issued by the National Weather Service in the US by making an HTTP GET request with URL

https://weatherkit.apple.com/api/v1/weather/en-US/37.775/-122.419?dataSets=weatherAlerts&country=US&timezome=America/Los_Angeles

and I get back the following JSON response:

{
    "weatherAlerts": {
        "name": "WeatherAlertCollection",
        "metadata": {
            "attributionURL": "https://weatherkit.apple.com/legal-attributionl.html",
            "expireTime": "2023-01-24T13:56:57Z",
            "language": "en-US",
            "latitude": 37.775,
            "longitude": -122.419,
            "providerName": "National Weather Service",
            "readTime": "2023-01-24T13:51:57Z",
            "reportedTime": "2023-01-24T13:51:57Z",
            "version": 1
        },

        "detailsUrl": "https://weatherkit.apple.com/alertDetails/index.html?ids=aa2dc3b7-fed9-5440-a4eb-5016e5b7fcf6&lang=en-US&timezone=America/Los_Angeles",
        "alerts": [
            {
                "name": "WeatherAlertSummary",
                "id": "aa2dc3b7-fed9-5440-a4eb-5016e5b7fcf6",
                "areaId": "caz006",
                "areaName": "San Francisco",
                "attributionURL": "https://alerts.weather.gov/cap/wwacapget.php?x=CA1266315CB698.BeachHazardsStatement.1266316AFFA0CA.MTRCFWMTR.37cfe8e9d94b8ab78ac93cb81ffbbd70",
                "countryCode": "US",
                "description": "Beach Hazards Statement",
                "effectiveTime": "2023-01-24T12:38:00Z",
                "expireTime": "2023-01-25T06:00:00Z",
                "issuedTime": "2023-01-24T12:38:00Z",
                "eventEndTime": "2023-01-25T06:00:00Z",
                "detailsUrl": "https://weatherkit.apple.com/alertDetails/index.html?ids=aa2dc3b7-fed9-5440-a4eb-5016e5b7fcf6&lang=en-US&timezone=America/Los_Angeles",
                "phenomenon": "Coastal",
                "precedence": 0,
                "severity": "moderate",
                "source": "National Weather Service",
                "eventSource": "US",
                "urgency": "expected",
                "certainty": "likely",
                "importance": "normal",
                "responses": []
            }
        ]
    }
}

A common problem is forgetting the country parameter. Weather alerts are official notices issued by government weather agencies and sometimes more than one government will issue alerts for the same location for reasons outside of Apple's control, so it is necessary to specify the country as well as the location.

  • Thank you for providing an example! Is it also possible to retrieve historical weather alerts? I have tried passing hourlyStart and currentAsOf but only current alerts are returned.

Add a Comment

Thank you. I was in fact forgetting the country parameter.

Well the documentation of the REST API says you need countryCode and not country. But it only works with country.

https://developer.apple.com/documentation/weatherkitrestapi/get_api_v1_weather_language_latitude_longitude

Docu is probably wrong. Country is also used for https://developer.apple.com/documentation/weatherkitrestapi/get_api_v1_availability_latitude_longitude

Also it it technical very challenging that a country value for alerts must be set as this information is not always available. A visitor to USA who has his phone still set a foreign language will have a device country value from the foreign language and therefore will not get any alerts for USA. It would be good if simply the local authority is used if the parameter is not set.

  • The country should not be based on a language or country setting for the device but rather on the location being requested. No matter how a user's device is set, it is entirely possible to request weather alerts for locations in multiple countries and no device setting would be correct for all of them. A better choice would be to use a reverse geocoding service to find the country for the location of interest.

Add a Comment

does the Weatherkit offer a webhook for push notifications?

Add a Comment