Alteryx: Dealing with multiple API’s

by Laine Caruzca

This week, our project involved linking to an API, cleaning the data in Alteryx and using Alteryx to launch this dataset into a dashboard we created in Tableau all within an Alteryx App. This blog post will talk about how to use two API’s by linking them together.

To clarify, an App on Alteryx allows a user to select parameters or to input a word which then filters through the data the user is looking for. For example, in my project, I wanted to allow the user to input their postcode and to get the weather information for their area.

This week, the biggest challenge was linking two API’s together on Alteryx. My initial idea was to link to a weather API called Dark Sky.

However, the API required the user to input their latitude and longitude values. This was not very user friendly, because, who actually knows the long and lat values of where they live? No one.

So, I had to link to another API that produced the lat and long values of a given postcode. This I could work with.

To link them together, I had to create a Macro from the postcode API. My workflow looked like this.

  • The first 2 ‘black’ icons are called Interface tools. They are what allows the user to input their postcode.
  • I used a text input tool that created a field for the URL being downloaded.
  • I then used a download tool to download the information from the API.
  • Since this was a JSON dataset, I then used a JSON Parse tool to get the information needed.
  • I then used a series of tools to transform and clean the data to give me just the long and lat values for that postcode.
  • Finally, I used a macro output.

I then had another workflow for the other API that generated the weather information. It looked like this:

Linking the API’s together

Now in this workflow, I wanted to link the two workflows together so that the lat and long values generated by the first API could then be used the generate the information from the second API.

This is what I did:

So, the macro that I created is the tool with the blue dot icon on the far left. I then used another interface tool, again allowing the user to type their postcode. When you use an interface tool, an action tool also shows up. In this action tool, I used the following configuration.

This basically means that you want the interface tool to update the value input in the macro.

However, I also linked the interface tool to a formula tool, which I placed right before the download tool.

So I will try to explain this bit as clearly as I can, because the logic needs a little thinking.

The reason why I put the filter tool just before the download tool is because we want the download tool to download the newly updated URL with the new long and lat values.

Now, in the filter tool, what we are trying to do is to re-create the URL, where we can update the long and lat values. So in the configuration section, this is what my formula looks like.

Now as you can see I copied and pasted the first part of the URL until the bit with the long and lat values, into the formula box and I wrapped this in a string.

Then, when it came to entering the lat and long values for the URL, I then inserted the fields [latitude] and [longitude] that was generated from the first API.

This meant that this URL would now update with a newly generated lat and long value when a user inputs their postcode.

This then completes the URL.

When we run this filter tool, it will then generate the correct URL to download the correct information.

I then created a workflow to clean the data and get the weather information I wanted.

I was then able to link this to a tableau dashboard by using the command tool in Alteryx. To see how you can do this, please see Lorna Eden’s blog post here.

So, there you go! Hopefully you too can now use 2 API’s together to get the data you want!

 

 

 

 

Avatar

Laine Caruzca

Sun 04 Nov 2018