With the help of cURL we can access the Nylas APIs in a fast and easy way. We only need a terminal and our Nylas credentials.
While Nylas offers awesome SDKs for Python, Node.js, Java, and Ruby, sometimes it’s good to learn Nylas by using cURL to make API calls. cURL—short for Client URL—is a command-line tool that lets you transfer data to and from a server with a variety of protocols. Many developers consider cURL to be simple to use and helpful for easily consuming new APIs; plus, it’s almost language agnostic so we can apply the concepts used in cURL to most language environments.
In this blog post, we’re going to see how to do the following:
Send emails with and without attachments
Read our inbox
Create a calendar and an event
Read and update contacts
Let’s jump in!
The first thing we need to do is go to our Nylas Dashboard, and select Playground.
We can also press Ctrl+K and type Playground on the search bar.
We can choose from some templates to help us get started.
Let’s start with Send email.
Working with email
The first option, Send email, is selected by default:
When we input our Access Token, we’re ready to send the email by pressing the green Run button:
If the cURL command was successful, we’ll get a JSON success response like this:
We can also verify success in our email account:
While we are in the Playground, we cannot change the content of the cURL command. However, we can copy everything and run it in our own local terminal, where we can for sure do some modifications:
Just like we saw above, we will get a success confirmation in our terminal that our email has been sent:
We can see that the email was sent from our account and not from a Nylas server:
You may be wondering by now… no attachments? I cannot send a funny picture? Well, of course you can! Read on to see how to do it.
Working with email and attachments
To send an attachment, we need to work with the Nylas files endpoint. In the terminal, go to the folder where your attachment resides and type the following cURL command:
Now, it is very important that we copy the id returned, as we’re going to use it to add the file to our email.
We can copy the playground example we saw above and modify it accordingly:
curl -X POST \
-H 'Authorization: Bearer <ACCESS_TOKEN>' \
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache' \
"subject": "From Nylas",
"name": "blag "
"name": "blag.nylas "
"body": "This email with attachment was sent using the Nylas email API. Visit https://nylas.com for details.",
Now we paste the command into the terminal:
We will receive a confirmation back:
And then we can simply check on our target email account:
We’ve sent an email with an attachment using cURL! What else can we do?
Reading our Inbox
We can also take a look at our inbox messages. In the Nylas Dashboard, select the “See conversation history” button:
Just like we did before, we can copy this code and run it in the terminal, with the option of changing some of the parameters. For example, we can use in=inbox as a query parameter in the URL to read exclusively from our inbox folder. Or we can use has_attachment=true to display only email containing attachments
We’ll get back—you guessed it—all emails from our inbox that have an attachment:
Nylas can do all kinds of great stuff with email, but it goes even deeper than that. Let’s turn our focus to using Nylas and cURL to work with calendars.
Working with Calendars
Back in the Nylas Dashboard Playground, let’s select See upcoming events. This cURL call will grab all the events happening one year into the future after the specified date (dates are specified as Unix timestamps):
But that’s not very helpful as by default it’s taking the auto-generated calendar. Let’s target a calendar created by us.
In our local terminal window, let’s run this cURL command which gets a list of all calendars in our connected account:
As we can see in the example, we’re searching using a query parameter in the URL. In this case, we’re searching for [email protected]; however, we’re using alvaro.t%40nylas.com … if you’re wondering why the %40: it’s just because we need to use percent-encoding (URL encoding) for all parameter values.
Running the command above, here’s what you’ll get (assuming that I’m one of your contacts!):
Now let’s say that we want to get the picture of the contact. First, grab the ID of the contact returned above, then add it to the following cURL command:
Once downloaded, we can use the open command to display the picture: $ open <image-filenmame>.
And now you can cURL up with Nylas!
I hope you liked working with cURL and the Nylas APIs. We have now learned how to work with emails, add attachments, look at our calendar events, and retrieve details about one of our contacts. If you want more information, please go to our documentation.
You May Also Like
Working with the Nylas Contacts API and Python
Super power the Nylas CLI with Fig
How to Streamline Communication Workflows and Integrate Automation Into Your CRM
Blag aka Alvaro Tejada Galindo
Blag aka Alvaro Tejada Galindo is a Senior Developer Advocate at Nylas. He loves learning about programming and sharing knowledge with the community. When he’s not coding, he’s spending time with his wife, daughter and son. He loves Punk Music and reading all sorts of books.
Strictly Necessary Cookies
Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.
If you disable this cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.
3rd Party Cookies
This website uses Google Analytics to collect anonymous information such as the number of visitors to the site, and the most popular pages.
Keeping this cookie enabled helps us to improve our website.
Please enable Strictly Necessary Cookies first so that we can save your preferences!