Where do you get the API Key for National Weather Service?
json - How do I get the hourly forecast from api.weather.gov for Texas stations or zones or offices or gridpoints or anything else? - Stack Overflow
NWS Integration API Key - Where to obtain ley?
Best API or DB for historical weather?
I want to use the NWS integration and it is asking for a API Key. I tried going to https://www.weather.gov/documentation/services-web-api but it doesn't tell me how to get the key. I see it says there's a link to the API, but it just goes to a site that doesn't have much to it. How do I get the API Key to use for the integration?
Looking at the api documentation found HERE and HERE, you are calling the /gridpoints/{wfo}/{x},{y}/forecast/hourly call which will return the hourly weather forecast for the specified weather office {wfo} at the specified x-y coordinates. You can find a list of the weather offices HERE. Finding the X-Y coordinates for the weather offices may be a bit more tedious to find on the web.
If you happen have access to the GPS coordinates that you are working with you can use the /points/{x},{y} API call to get the information on the closest weather office to then pass to the /gridpoints/{wfo}/{x},{y}/forecast/hourly API call.
The flow of your application can look something like this:
Step 1: Get your map Geo coordinates. In my case, I am at 35,-106
Step 2: Make a call to the weather.gov API: https://api.weather.gov/points/35,-106. You will be presented with some JSON data. Look for the cwa key in the properties object. That will be the forecast office to pass into the next api call. In my case, the key is ABQ. You also need to find the gridX and gridY keys in the properties. These are the XY coordinates that you will use for the {X},{Y} parameters in the API call. In my case X = 121 and Y = 112.
Step 3: Make the final call to the weather.gov API: https://api.weather.gov/gridpoints/ABQ/121,112/forecast/hourly
As long as you have the latitude/longitude of the location you want the forecast for, then:
- Get the point metadata from https://api.weather.gov/points/{lat},{lon}
- Follow the link in the
forecastHourlyproperty to get the forecast
This is preferable to constructing the URL as in the other answer, as your program won't break if the URL scheme changes in the future.