Fig Workflows and the Nylas CLI

Learn how Fig Workflows can help you improve your productivity and boost your development when combined with the Nylas CLI

Fig Workflows and the Nylas CLI

You might know what the Nylas CLI is, if not, check out this blog post on Working with the Nylas CLI. And what about Fig and its relation with the Nylas CLI? Here’s another blog post on how to Super Power the Nylas CLI with Fig. Now you may be wondering, what is a Fig Workflow? This blog post is here to discover how you can use Fig Workflows to further Super Power the Nylas CLI.

What are we going to talk about?

Before you proceed

What is Fig Workflow?

Setting up our first Fig Workflow

How does the Nylas CLI fit in?

Creating a Webhooks Workflow

Before you proceed

Note that Fig Workflow is currently in Beta, so you may have access to Workflows by the time you’re reading this blog post.

What is a Fig Workflow?

A Fig Workflow is the easiest way to automate your daily developer tasks. By using workflows you can define commands with parameters to avoid typing repetitive commands and help avoid having to recall different commands. Let’s see an example:

By typing:

$ curl

We can get the weather in a nice terminal format:

But, who wants to remember that command? A Fig Workflow can help.

Setting up our first Fig Workflow

Simply, type fig on the terminal window. This will open the Fig dashboard, where we can press Workflows:

Then we can either press New Workflow or even Template Workflow for some nice examples:

When we create a new workflow, we need to name it of course:

On the Script section we need to add the following code:

if [ "{{location}}" == " " ]; then

And add an input parameter called location:

It will be saved automatically. So now we can call it from the terminal by typing:

$ fig run

And then choosing our Weather workflow from the list:

Our Location parameter will show up. If we want our default location, we can simply press Spacebar and then Return:

Or we can pass a city name:

And it will be executed:

How does the Nylas CLI fit in?

That’s a great question. In the Nylas CLI we have a lot of commands that we can use to read emails, fetch contacts and create events. Sometimes we need to pass extra parameters and most of the time it’s difficult to remember them all.

Of course, the Nylas CLI is integrated with Fig, so we get autocompletion, which makes our lives easier, but, with Fig Workflow we can make our lives even easier.

Let’s create a workflow to read the contacts in our address book, so just the manually created contacts and not the auto-generated contacts. We can call the workflow Read Contacts:

The Script will be:

nylas api contacts get --source address_book --limit 1

Where the limit will be our input parameter.

Now, we will have two workflows:

And passing the limit:

This will return the requested number of contacts:

Now, at Nylas, we’re always aware of what developers need and want, and developers are using the Nylas CLI to work with webhooks.

So let’s create a workflow to help us when working with webhooks.

Creating a Webhooks Workflow

First, we know that we can create a script to help us make the output more readable (for context, read Testing Webhooks using the Nylas CLI and Ruby).

But depending on what we use, the default port might be different, for example: 8000 for PHP, 4567 for Ruby and 5000 for Python.

We’re going to create a new workflow called Webhooks and use the following script:

case {{port}} in
nylas webhook tunnel -f
nylas webhook tunnel -f
nylas webhook tunnel -f
nylas webhook tunnel --print

Where port will be our input parameter:

When we run it, we can pass php, ruby, python or none.

Here we are using php:

And here we’re using none:

Cool, huh? Wanna share your own Workflows? Tag us on Twitter using our handle @nylas ????

For more information about the Nylas CLI, visit our documentation Nylas CLI.

Don’t miss the action, watch our LiveStream Coding with Nylas:


You May Also Like

Nylas_Gartner Cool Vendor
Nylas recognized as a Cool Vendor in the Gartner 2023 Cool Vendors in Composable Customer Engagement Platforms
How to manage your Contacts using Reflex (Pynecone)
2023 Compliance Audits
Nylas’ 2023 compliance audits: A benchmark in trust and security

Subscribe for our updates

Please enter your email address and receive the latest updates.