Docs
Search…
API data (JSON)
Retrieve data from any API source and write queries on top of it using SQL

API Data Source

LogicLoop lets you query any API that returns data in a JSON format as a data source. That means you can query services like Slack, Mixpanel, Stripe, and Twilio to retrieve data and write rules on top of that data using SQL.
First, create a new API (JSON) based Data Source and enter any Authorization information needed.
For most APIs, you will enter "Authorization" as the Authorization Header Key. However, some APIs give their auth header a different name such as "Authorization-Token" or "X-Token" or "Service-X-Token" etc.
For most APIs, the Authorization Header Value will be your API key or token e.g "XXXXXX". However, some APIs require you to append the word "Bearer XXXXXX" or "Basic XXXXXX" before your token.
Now, all you have to do is create a new rule and express your API call in YAML format. The results of that API call will be parsed as JSON into the results table below.
In this example, we made an API call to retrieve a channel's conversation history on Slack:
1
url: "https://slack.com/api/conversations.history"
2
params:
3
channel: "C01M88G0NDX"
4
path:
5
messages
Copied!
This API call is equivalent to running something like this via CURL:
1
curl "https://slack.com/api/conversations.history?channel=C01MP8G0NDC" -H "Authorization: XXXXXX"
Copied!
The Slack API will return a result that looks something like this.
1
{
2
"ok": true,
3
"messages": {
4
type: "message",
5
subtype: "bot_message",
6
text: null,
7
ts: 16309440202,
8
username: "logicloop",
9
...
10
}
11
...
12
}
Copied!
We've added the path: messages setting in order to access the nested messages object. The results populate this table below:
You must format your query in YAML syntax. Parameters that are available include:
  • url (string) - the URL endpoint you want to hit
  • method (string) - the HTTP method to use (default: get)
  • headers (dictionary) - headers to send with the request
  • auth (array) - basic authentication username/password (e.g: [username, password])
  • params (dictionary) - query string parameters to add to the URL path
  • data (dictionary) - values to be sent as the request body
  • json (dictionary) - same as data except that it's converted to JSON
  • fields (array) - specific fields you want to pick from the results
Here is an example of a sample POST request:
1
url: "https://myendpoint.com/api/users"
2
method: post
3
headers:
4
X-Token: "XXXXXXXXXXXXXXXX"
5
data:
6
name: "Maddie"
Copied!
Now that you've retrieved data from your API source, you can set up an action to trigger directly from the data.

Read from Slack API

Create a pre-configured app

The most common way of interacting with the Slack API is by creating a Slack App Integration. Begin by navigating to the this tutorial on How to quickly get and use a Slack API token. Scroll down to the Create a pre-configured app section and click Create app.

Configure your Slack App

Next, select the workspace that you want to interact with (read from or write to), and click Next. To give the app a recognizable name and description, click Edit Configurations and change the values of name (you will need this later) and description. Finally, click Next, then Create.

Get your Slack API Token

Under Install your app, click Install to Workspace, and select Allow. At the top of the screen you should see a message telling you to head back to the tutorial. Click the link in the message.
If you scroll down to the section Using your token, you can find the API token populating a black box (starting with xoxb). Save that token to somewhere safe, you will need it.

Add integration to a channel

Open Slack and select the channel that you want LogicLoop to interact with. Click on the title to open the a popup with channel information.
Select the Integrations tab and click Add apps.
Start typing the name of your Slack App, or scroll through the In your workspace section until you find it, and click Add. The channel will have a message confirming that the app was added.

Create the Slack Data Source

Go to Data Sources > New Data Source. and choose API (JSON). Give it a name, add Authorization as the Authorization Header, and use add the API key (with the Bearer prefix) as the Authorization Value.

Query the API

You need the Channel ID too access the messages of a channel. Find it in Slack by clicking on the channel title and scrolling to the bottom of the About tab.
Use the URL https://slack.com/api/conversations.history with a parameter for the Channel ID. Set the path to messages.

Query APIs with SQL

Alternatively, once you've retrieved the data you want from your API, you can write another rule on top of these results using SQL to combine data or use for further manipulation.