APIs

by Jessica Haire

API stands for Application Programming Interface. APIs are an interface that allow us to interact between two or more pieces of software. They act as an intermediary and are there for us to retrieve data from one or multiple sources. Think of a waiter who takes your order, goes to the kitchen, interacts with the cook and then brings you your meal. You have your meal which was prepared by the cook, but you didn't have to see nor talk to the cook. The waiter did the magic and so does the API.

There's a great video on YouTube that helped me make sense of this topic. You should check it out and build along. I always use it as my reference point whenever I have an assignment on APIs. It's a very thorough tutorial by Robbin Vernooiji of the Information Lab. Here's the link:

https://www.youtube.com/watch?v=LQMijJd5y5g&ab_channel=TheInformationLab

The first thing to bear in mind when you want to make an API call is to find and read the documentation. This is where you'll find things like the base URL or what URL to use depending on your endpoint.

Looking at the icanhazdadjoke.com documentation, some endpoints include:

https://icanhazdadjoke.com/ fetch a random dad joke. https://icanhazdadjoke.com/j/<joke_id> fetch a specific dad joke. https://icanhazdadjoke.com/search - search for dad jokes.

When you have your URL, you can head over to Alteryx, grab a Text Input tool and manually type in URL as your header and the the URL you copied as the vlaue and Run. This will return a record with the URL. Make sure you see 200 OK which means you haven't got an error, otherwise you'll have to troubleshoot your URL.

Get a download tool and attach to the text input tool and it will auto populate itself and open it's configuration window. The field that we want to download is the URL, so make sure URL is selected.

There are three response formats:

text/html- HTML response (default response format)

application/json- JSON response

text/plain - Plain text response

In our case we'll use application/json because Alteryx has a great JSON Parse tool. In the configuration window, go to the headers tab, click Add and then type in Accept under Name and application/json under Value and Run. Our output will consist of two new rows: JSON_Name, and JSON_Valuestring. The former contains our headers and the latter our values. From this point, there are a number of options for you depending on what you're trying to achieve. Including using other tools like the Text To Columns tool and the Cross Tab tool.

It's good practice to cache and run your workflow when you're using APIs/URLs to avoid lengthy loading times, and to avoid reaching a possible rate limit and throttling.

Wed 28 Sep 2022

Tue 27 Sep 2022

2 mins read

Mon 26 Sep 2022

Sun 04 Sep 2022