Getting Started

Welcome

Welcome to Flex.io!

Flex.io is a service for stitching together functions with out-of-the-box helper tasks that take the pain out of OAuth, notifications, scheduling, local storage, library dependencies, function chaining and other ‘glue’ code.

These serverless functions and tasks are defined using Flex.io pipes. Once defined, pipes can be scheduled or triggered to run with an API request, webhook or by sending an email.

What is a Pipe?

A pipe is a collection of tasks that run sequentially. The most commonly used task is the Execute Task, which runs custom Python or Node.js (Javascript) code. The Execute task can also can read and write from data sources like cloud storage, databases and APIs using Flex.io Connections. Additional helper Tasks can be configured to issue requests, convert file formats and send email notifications.

In this getting started guide, we’ll show you how to build and run your first pipe. Then we’ll point you to additional resources to help you create your own custom serverless pipes.

Sign Up for an Account

To begin, you may sign up for an account here.

Enter your name and choose a username between 3 and 80 characters long. The username is your namespace for your pipe and connection paths, when you call them remotely.

Then, enter your email address and choose a password with at least eight characters and one number. Then, click the Sign Up button.

Thereafter, you may sign in to Flex.io here.

Get Help

Got more questions? Check out our FAQ for some quick answers. And, feel free to message us from the icon in the lower-right of this page; we’re happy to help.

Ok, let’s get started!

Build your First Pipe

To get you started, we’ll create a simple pipe that gets enables you access Gmail via OAuth, apply Python functions to Gmail and then receive an email notification with the results.

Because of Flex.io’s built in Tasks, it’ll only take a couple minutes for you to create and deploy. Specifically, you’ll do the following:

  1. Get an OAuth token from Gmail
  2. Add a Python function to read messages from Gmail
  3. Update the function to read message content
  4. Add a second Python function that uses pandas to format the results
  5. Create an email notification with the table
  6. Deploy the pipe with the built-in scheduler

To begin, first sign in to your Flex.io account and navigate to the Pipes page, which lists all of your pipes.

Getting Started: Pipe List

Select the “New Pipe” button from the upper right to access the Pipe Builder.

Getting Started: Pipe Builder New

For this tutorial, you’ll start with a blank slate. So, first delete the “hello world” Execute Task by hovering over the Task and clicking the delete icon at the right.

You should now see an empty pipe and an option to choose a task. Now let’s start building!

Get Gmail OAuth Token

To work with Gmail’s API, you’ll need code to generate a Gmail OAuth token. To do this, click on the OAuth Task.

Getting Started: Select OAuth Task

If you have already created a connection to Gmail, you can simply click on it from your list of existing connections. Otherwise, click on the the “Set up a New Connection” button to pop up a dialog with OAuth connection types. Select the “Gmail” icon and you’ll get a configuration panel.

Getting Started: Gmail Connection Setup

Click the “‘Authenticate your Gmail Account’ button and then follow the Gmail prompts to authenticate. Once authenticated, click the “Create Connection” button, which will take you back to the OAuth dialog.

We’ll be using Python for this example, so make sure it is selected. Finally, click “Save Changes” and the OAuth dialog will create an Execute task for you to get the Gmail OAuth token, which will look something like this:

Getting Started: Gmail OAuth Code

Here is what’s happening with this code:

def flex_handler(flex):
connection_identifier = 'my-gmail'
auth_token = flex.connections[connection_identifier].get_access_token()
flex.end(auth_token)

To test your code, click the “TEST” button at the top right of the Pipe Builder to run your pipe. After running, you’ll see your OAuth refresh token in your output.

Add a Function to Read Messages

With the OAuth token, you now have the ability to talk to Gmail. Next we’ll create a function that gets a basic list of the last 10 messages from your account. To do this we’ll modify the existing OAuth code in two steps.

  1. In your Execute task, select everything above the line def flex_handler(flex): and then add the following snippet. This loads the Python modules needed to run this example.
  1. Then, select everything after the line auth_token = flex.connections[connection_identifier].get_access_token()
    and replace it with the following, which gets a basic list of messages from Gmail using your OAuth token

Your script should now look like this:


After you’ve copied in your code, save your changes and then click the ‘TEST’ button again to re-run the pipe. After a couple seconds, you’ll receive a list from Gmail with the ten most recent messages, which will look something like this:

[
{
"id": "1666a25a9sbc6ec9",
"threadId": "1666a25a9sbc6ec9"
},
{
"id": "16668fa8b44023d7",
"threadId": "16668fa8b44023d7"
},
{
"id": "166641124af6003d",
"threadId": "166641124af6003d"
},
{
"id": "1665fe7f799rdaa9",
"threadId": "1665fe7f799rdaa9"
},
{
"id": "1665cb45a53a11a7",
"threadId": "1665cb45a53a11a7"
},

...

Update the Function to Show Content

Now that you have your basic message IDs, update the function to show the content related to those messages. To do this, modify the same Execute Task as follows:

  1. In your Execute task, select everything after the line message_list_page = message_list_url
    and replace it with the following, which will get the messages fields and populate them with the email information:

After you’ve copied in your code, save your changes and then click the ‘TEST’ button again to re-run the pipe. After a couple seconds, you’ll receive your email information in JSON format, which will look something like this:

[
{
"from": "\"Mom & Dad\" <momdad123@aol.com>",
"to": "George Faust <gfaust@gmail.com>",
"date": "Thu, 11 Oct 2018 17:00:48 +0000",
"subject": "FWD: RE: FWD: FWD: Send this to 10 friends or the panda won't survive."
},
{
"from": "\"Politics Today Newsletter\" <politics@cnn.com>",
"to": "gfaust@gmail.com",
"date": "Wed, 10 Oct 2018 21:09:28 +0000",
"subject": "Red or Blue, Dihydrogen Monoxide Affects us All."
},
{
"from": "\"John Smith\" <john@smith.io>",
"to": "gfaust@gmail.com, joe@johnson.com, susanmccook@yahoo.com",
"date": "Fri, 12 Oct 2018 21:17:20 +0000",
"subject": "Any of you happen to grab my phone last night? :/"
},

...

Add New Function to Format Results

Now that you have message data from Gmail, it’s time to format it. This will be a distinct process using the pandas library for Python, but Flex.io makes it easy to chain together logic by passing an output of any given task to the input of the following task.

Do the following to add a reformatting function:

  1. Add another Task by clicking the “+” icon below your existing Execute task. Then, select another Execute Task.

  2. Delete “hello world” sample code and replace it with the following snippet, which converts the email results from JSON and displays it as a text-based table.


After you’ve copied in your code, save your changes and then click the ‘TEST’ button again to re-run the pipe. After a couple seconds, you’ll see a reformatted list of your Gmail headers by date that looks like this:

date	subject
2018-10-12 21:17:20 Red or Blue, Dihydrogen Monoxide Affects us All.
2018-10-11 17:00:48 FWD: RE: FWD: FWD: Send this to 10 friends or the panda won't survive.
2018-10-10 21:09:28 Any of you happen to grab my phone last night? :/
...

Add Email Notification

With your correctly formatted data in hand, you’ll now finish off the pipe by adding an email notification, which will take the output from the previous execute step and pass it into the body of the email.

Do the following:

  1. Add another Task by clicking the “+” icon below your second Execute task. Then, select the Email Task.

Fill in the dialog with your name and email address. In the message area, add the following snippet:

Here are your most recent message by day:

${input}

You should now have an Email task that looks something like this:

Getting Started: Email Task

After you’ve saved your changes, click the ‘TEST’ button again to re-run the pipe. After a couple seconds, check your inbox for the email notification.

Deploy the Pipe

Congratulations, you’ve defined your first serverless pipe!

Now, you can deploy this pipe into production. Flex.io gives you multiple options for Deployment. However, to finish up this guide, we’ll simply schedule it as follows:

  1. First, turn on your pipe to activate it.

  2. In your pipe, scroll down to the bottom Deployment section and check the box next to Run on a schedule.

  3. Finally, click on “Edit” and set up the schedule you would like to use. By default, this pipe is scheduled to run every day at 8AM UTC. Update this by clicking on the “EDIT” button to configure the Scheduler and set it to run every five minutes. Click Save Changes and your schedule will update in the Pipe Builder.

Getting Started: Deploy using the Scheduler

Now that your pipe is on and scheduled, you’ll start seeing emails to your inbox every five minutes. Once you’ve seen how it works, simply go back to the pipe and turn it OFF.

Learn More

Congratulations, you’ve created, run and deployed your first pipe!

While simplistic, this pipe demonstrates the end-to-end nature of a pipe and how Flex.io not only runs your functions in sequence, but also provides building blocks out-of-the-box, like OAuth refresh tokens, notifications and scheduling.

Now that you have the basics, you can dive into the additional resources below to build your own custom pipes. Should you have any questions at all, don’t hesitate to ask, we’re very happy to help!

Reference Material

To take a deeper dive into the core concepts of Flex.io data feeds, you can take a look at the following guides:

Flex.io API reference docs can be found here:

Tutorials and Examples

In addition to the reference material above, you can also take a look at some real-world use cases. Tutorials will provide step-by-step details on how to build various serverless pipes. Examples provide a variety of common starter functions that you can copy and paste into your Execute Tasks.