New PWS API - Station ID with forecasts

  • 1
  • Question
  • Updated 9 months ago
With the new PWS API, is it possible to query based on the station ID? The documentation only lists things like coordinates, city based IDs and postcodes as far as I can tell. I know we can get the coordinates from the other PWS specific endpoints, but allowing a station ID for forecasts would make code a lot cleaner
Photo of Shea Smith

Shea Smith

  • 3 Posts
  • 0 Reply Likes
  • unconcerned

Posted 9 months ago

  • 1
Photo of Victoria Gardner

Victoria Gardner, Official Rep

  • 658 Posts
  • 93 Reply Likes
Yes.  If you look here, for instance:
https://docs.google.com/document/d/1KGb8bTVYRsNgljnNH67AMhckY8AQT2FVwZ9urj8SWBs/edit

under "URL construction" it gives you an example of a station ID being used.

Victoria Gardner
victoria.gardner@ibm.com
Photo of Shea Smith

Shea Smith

  • 3 Posts
  • 0 Reply Likes
I tried using the stationId parameter with forecasts, however I got a insufficient parameters message. I'll have to double check the capitalisation I used.
Photo of László Gönczöl

László Gönczöl

  • 6 Posts
  • 1 Reply Like
Me too. Just on a different way:
I just tried to get the current conditions of my own PWS in JSON format according the instructions in the doc linked above by Victoria and  got the result: "CDN-0001","message":"Invalid apiKey."
Does it it mean my old API key is not valid anymore for V2? Can I get a new one or it's a dead end?

Photo of Victoria Gardner

Victoria Gardner, Official Rep

  • 658 Posts
  • 93 Reply Likes
Your old WU api key will not work on the new API.  Send me an email with your PWS ID.

Victoria Gardner
victoria.gardner@ibm.com
Photo of Shea Smith

Shea Smith

  • 3 Posts
  • 0 Reply Likes
You will have to get a new one, but you need to own a PWS, or buy access to the Weather.com api
Photo of Dan Tripp

Dan Tripp

  • 5 Posts
  • 0 Reply Likes

The API for forecasts doesn’t include station ID as one of the options for specifying location in the URL.  See https://goo.gl/QBN6Rc.

This is different than the requests for current conditions and history.  I suppose it makes sense, since the forecast is for an area, whereas history and conditions are specific to a particular station.  However, it is somewhat inconvenient since it means you need to make two API calls:  one to get the location of a station, and another to get the forecast.  In practice for me it’s not a big deal because I can use my station’s latitude/longitude rather than its ID when getting a forecast.

   
Photo of joegr

joegr

  • 22 Posts
  • 9 Reply Likes
I can get current conditions with my new api key, but every way that I have tried to get the 5 day forecast so far results in: Access Denied.  It's probably something stupid that I am doing.  Could you post an example request URL for a 5 day forecast that i could paste my key into that does work?  I don't care what location you use, I can figure out how to change that.
Photo of Victoria Gardner

Victoria Gardner, Official Rep

  • 658 Posts
  • 93 Reply Likes
Okay, you're going to have to trust me to some extent, because I can't expose my key, but this call works just fine.  (I also took off the https:// so the Forum would stop interpreting it as a real URL.)

api.weather.com/v3/wx/forecast/daily/5day?postalKey=01810:US&units=e&language=en-US&format=json&apiKey=MYKEY

The documentation for the call https://docs.google.com/document/d/1RY44O8ujbIA_tjlC4vYKHKzwSwEmNxuGw5sEJ9dYjG4/edit#
has all "7day" in it -- that should be replaced with "5day", as the PWS API has only 5day set up for it.

I hope that helps!

Victoria
victoria.gardner@ibm.com


Photo of joegr

joegr

  • 22 Posts
  • 9 Reply Likes
Okay, that works.  Thanks.  I was trying to do it with coordinates, but zip code is fine.
Photo of Victoria Gardner

Victoria Gardner, Official Rep

  • 658 Posts
  • 93 Reply Likes
There are examples for that, too, in the documentation.  I just wanted something that was easy to read.

--Victoria