Working with APIs in thestoryline.io

Working with APIs is the coolest part of thestoryline.io according to me because I don’t have to sit and work on new ideas everytime I want to build a new skill. Since there are quite a few gaps on how to use APIs with the tool, I’ve decided to write a lengthy article which covers every single kind of API request you can make and play around with the responses in your skill. 

For the non-programmers, an API with a GET method means you can directly call the URL and you will get the response in JSON format. And, an API with a POST method means you will send some data to the URL using the headers and a URL through which you will receive a response in JSON.

POST is mostly used where there is Authentication like an API Key or an OAuth request to use the API.

1. Simple GET API Example

API: https://uinames.com/api/

The configuration in Storyline should be as shown below:

To use this as voice from Alexa, following should be the configuration

 

2. Complex GET example

API: https://randomuser.me/api/?results=2

This API returns a nested JSON and I am using beautifyjson.com to make it readable and the parameters we will need are shown below. As per the URL, this API returns two random user profiles.

The configuration in thestoryline.io should be as shown below. Please note that to get two responses, we will use 0 and 1 as we don’t have looping mechanism yet in the tool.

UPDATE: You can now just say “random” instead of “0” or “1” from the results to get a random result. 

Finally, the flow in storyline should be something like this. Feel free to customize it that way you need.

3. Google Sheets to StoryLine using http://gsx2json.com/

For this example, I am using dummy sheets with some random data and let us see if we can pull them into StoryLine using the API. The best part about using google sheets as an API is when you want to update your content, you don’t have to deploy it back to the store and all. Just update the sheet and the skill will continue to work as is.

The sheet I will be using is: https://docs.google.com/spreadsheets/d/1s4J9QXrYiDqUVS3V_JxluoYs-1QIOiHbhOrJxzAF7gQ/edit?usp=sharing

The ID is 1s4J9QXrYiDqUVS3V_JxluoYs-1QIOiHbhOrJxzAF7gQ

The API URL will be http://gsx2json.com/api?id=1s4J9QXrYiDqUVS3V_JxluoYs-1QIOiHbhOrJxzAF7gQ

Setting up this API in StoryLine

The diagram in storyline will look something like this:

To make JSON readable, you can use beautifyjson.com or JSONViewer chrome extension. And if you don’t know where to get new ideas or APIs from, visit https://github.com/toddmotto/public-apis

Hope the above help. Comment below if you a different kind of an API and I’ll help you figure out the possibility of using it in thestoryline.io

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.