After a week of intensive training on API, web scrapping and Spatial in Alteryx, on Friday morning, we were tasked to present a dashboard demonstrating all the above by 3PM. There were plethora of ideas floating in my mind and converging to one was indeed a challenge.

For all that love I have for twitch streams, I decided to connect to twitch API. After failing to connect for 30 minutes. Boom! Here’s the news, Twitch API uses OAuth 2.0! So, quick change of plans, I switched to another simple API for the preso.

However, failure to connect to twitch kept haunting over the weekend and made me realise that I need to understand the concepts behind connecting to API using OAuth2.0 Authentication.  Hence, this blog to unravel and simplify the concepts and connect using Alteryx.

Choosing the Auth flow:

Though there are many authentication flows within OAuth2.0, when connecting with Alteryx we should always use Client Credentials Flow, which follows the concepts of Machine-to-Machine (M2M) applications.

After creating a developer account in twitch, created an application in the developer console which then provided a Client-Id and Client secret. (just a two-step process)

Understanding Access Tokens:

The flow chart below will help you get a comprehensive understand on each step and the process associated while connecting through Alteryx

Download Tool Setup – Receiving Token :

I find setting up download tool correctly to retrieve data is the tedious process, hence, I will head straight to download tool to explain the setup. The Text input tool will contain fields as shown below to retrieve token and the pictures following it are the download tool setup.

Text Input Tool:

Drag text inpput tool and create four columns as below.

Formula Tool:

In the formula tool create a new column concatenating as below.

Download Tool: Basic Tab

Select the URL column (Contains URL to receive token) in the URL field. 

Download Tool : Payload Tab

In the Payload tab, select “Take Query String/Body from field” and in the drop down choose the column “post” which was created in the formula tool .

Below is the initial flow to receive access token.

Output received with access token, will be used in flow along with API endpoint.

Download Tool Setup – Passing API :

Append the received token to the API endpoint and pass through another download tool to receive the data.

I’m interested only in twitch Live streams data, so, my API request is as follows. By default, the following request will provide top 20 most active streams. The results can be increased by adding optional query parameters to the API request

curl -X GET 'https://api.twitch.tv/helix/streams' \
-H 'Authorization: Bearer <Received from Oauth server>' \
-H 'Client-Id: CLIENTID'

Using the Formula tool, concatenate the work “Bearer” to the received token and name the new column as “Authorization”

Note: Field Name for header should match the header (-H) specified with the above request.

Download Tool: Basic Tab

In the Basic Tab, Select the column “Endpoint” (Which was created using Text Input Tool) in the URL field. 

Download Tool: Header Tab

In the Header Tab, Select the Column “Authorization” (Which contain the word ‘Bearer’ and the Token received from the initial flow) and “Cliend-Id”.

Download Tool: Payload Tab

Since twitch requires API request in the “Get” action, select “Get (or FTP)” from the HTTP action’s drop-down options. 

Output :

Here’s the link to download Alteryx Macro flow and Tableau Dashboard.

Alteryx: Twitch Macro

Tableau:  Twitch Top20 Live Stream

Feel free to drop me some comments if you find any easy or alternate methods.

Shiva Ravi
Author: Shiva Ravi

Shiva, a graduate in Electrical and Electronics Engineering, had an exciting Oil Industry career for over a decade exploring ocean bed through marine seismology. Being an Instrumentation specialist in International waters, he found his passion for data visualization while working with binary seismic data. Recently, in a short stint as a Technical Asset Manager, he discovered Tableau to manage the ridiculously diverse scientific equipment in the Global marine warehouse. He refers to inventory planning as finding a needle in the haystack, and Data analytics is like having a wand in hand. In a quest for learning, Shiva found Data school, which paved the way for the most-awaited career switch as Data Analyst. He is currently pursuing Masters of AI (Part-time) from Western Sydney University, and in his spare time, you can spot him cycling, running or designing logos. Recently, he tried his hand in cooking and took an interest in exploring cuisines. If there is something he cannot live without, that would be coffee!