What is an API?

API stands for Application Programming Interface. In simple terms, an API is a set of rules and protocols that allow different software applications to communicate with each other.

Think of an API as a waiter in a restaurant. When you go to a restaurant, you don’t go into the kitchen and tell the chef exactly how you want your food cooked. Instead, you tell the waiter what you want, and the waiter communicates your request to the kitchen. The kitchen then prepares the food according to the recipe, and the waiter brings the food back to you.

Similarly, when one software application needs to access data or functionality from another application, it can’t go directly into the other application’s code and make changes. Instead, it uses the API to communicate with the other application and request the data or functionality it needs. The other application then responds to the API request with the data or functionality that was requested.

What is the process of connecting to an API using Alteryx?

In general, the following steps are required:

  1. Determine what endpoint you are interested in
  2. Text Input tool including the website
  3. Download tool configured with appropriate authentications (eg. API key, headers)
  4. JASON parse tool
  5. Data cleaning, transforming, and analysing to extract what is required

I will now provide you examples on how to read API documentation.

Example 1: Dad Jokes API

Documentation URL: https://icanhazdadjoke.com/api

The endpoint we are interested in is to fetch a random dad joke:

For this example, we need no authentication but we need to specify a header to know that we need a json format response. This can be done in 2 methods:

In the download tool, you can specify the “accept” header with the value being “application/json”

Alternatively, we can create a header into the input text

That will produce this from the browse tool

The 200 OK means that it was successfully retrieved it from the API and ready to be parsed and data wrangled.

Now lets look at another endpoint within the documentation to demonstrate steps 4 and 5

Here the text input URL is https://icanhazdadjoke.com/search and so we connect to that using the same headers and process as above.

After adding the JSON parse tool and running it, you are going to notice there are 33 pages of dad jokes

We will need to modify our workflow to allow us to get all 33 pages.

We first use a filter tool to just select the pages and then a select column just to extract this number of 33

We need to modify the URL to account for each page and this can be done by the generate rows and appending it as such with an append tool and formula:

You can then use a JSON parse to extract all the necessary details for your data analysis

Thank you 😊

Nam Nguyen
Author: Nam Nguyen