Tag Archives: weather

Weather Underground Part 1: Invoking a GET method on a REST web service /w an API key in vCO

Consider this part 1 of 2 using Weather Underground.   First we need to gather data.

Feb 22 2014 – Typo in workflow name updated.  Thanks Phil

This post is a bit less exciting than the last FOAAS post. The concept here is important to grok however to be able to build on and do anything more advanced.

Introducing the REST interface for Weather Underground.  The API reference is here.  This page gives a good visual example of forming a API request and seeing the return as JSON.


Awesome, simple enough.  Shouldn’t be too different than dealing with curse words.     Because I always have been and always will be a lazy sys admin, we’re going to build on existing modules.   Add the Weather Underground host to vCO:


And form the URL in an REST operation in vCO as follows.  Note we’re using parameters in the URL template for KEY, STATE and CITY.  This operation is GET http request.


Now if you haven’t done it already, we need to sign up on Weather Underground for an API key.  Most web services work this way.  Instead of doing http authentication, you have a long unique key that you pass to prove you are who you are so they can track you.    It’s free on this site for 500 calls per day and 10 calls per minute.  Perfect.  Do that here.

We have our key, let’s test our connection with the built in ‘Invoke a REST Operation’ workflow.  Use the API key you were give, put in a State and a City:


And if all goes well, in the logs we should see the JSON formatted output (remember the last line of the workflow to posting the response as a string).  Snippet of the output:


Excellent!   This gives us a lot to work with.   Now let’s make this more real.  Duplicate this ‘Invoke a REST operation’ to one of your own, I call it ‘Invoke REST 2’  (never-mind the #2, i’m blogging this out of order as I’ve already done part two of this blog post).   I create a brand new workflow that passes parameters to that one to show how to nest workflows.

But first let’s modify the new ‘Invoke REST 2’ workflow.  Through some trial and error I figured out how to address individual parameters that we are returned in the JSON response.  For example, to make this stuff more meaningful it would be great to get the temperature in fahrenheit.   So we run the JSON.parse subroutine, and pull out the data as such.  Also we’re going to grab the time and location:


Now just to prove it still works, we can run just this one workflow real quick, pass the parameters and we get:


Excellent (and BRRRRR it’s cold this morning.  What the heck, winter is here?!)     Now that we’re doing something a little more fancy with the data, let’s create this brand new workflow I alluded to.   I’m calling this ‘Weather Underground 001’.

This workflow will have attributes for the api key, the name of the rest operation that we added, and the message body (this will be used later to pass data further along the workflow).  These are the hard coded attributes for this workflow.


The inputs we’re going to prompt for all City and State:


The outputs (irrelevant for this part as we are not passing them anywhere, but important for part two), are as follows:


And now some of the awesomeness of workflows – the “smart visio” schema.   This is how we drop elements into the workflow to do work.  For this part we’re just using the ‘Invoke REST 2’ workflow, so drop that in there:


Staying a bit high level for now, we need to connect up what is being passed into and out of this workflow with the Visual Bindings tab.  This is where we tell it what we need to do with city, state and key (and what the name of the REST Operation is).   This is also where we get the message variable we will do something with later.

This concept is key to using vCO as it’s intended.  We are re-using workflows, not re-creating them.  So there is no special scripting to do as it was already done in the workflow we embedded.


Save the workflow and increment the version.   Run this guy and you should see similar output to when we just ran the embedded workflow stand alone:


Still cold!    Awesome.  This is how we can connect to a REST web service, use an API key and pull out a specific value or three.    In the next part we will show embedding a second workflow and passing a value to that one to do some work with.

Tagged , , , ,