The developers'

API Guide

Everything you need to know about building, purchasing and integrating with APIs.

What is an API?

An application programming interface (API) is a set of rules and protocols for building and interacting with software applications. APIs enable different software systems to communicate with each other, allowing for data exchange and functional integration without requiring the end-user to understand the underlying code.

APIs have become the backbone of modern software development, enabling developers to leverage existing functionality and services without reinventing the wheel. They facilitate modularity, scalability, and innovation, allowing developers to build complex applications more efficiently by integrating with third-party services.

API Example

The following API examples show how to return the five most recent email messages from an account’s inbox by making a request to the Nylas Email API.

Node.js

Ruby

Python

Java

Curl

Response

app.get("/nylas/recent-emails", async (req, res) => {
 try {
   const identifier = process.env.USER_GRANT_ID;
   const messages = await nylas.messages.list({
     identifier,
     queryParams: {
       limit: 5,
     },
   });

   res.json(messages);
 } catch (error) {
   console.error("Error fetching emails:", error);
 }
});
require 'nylas'

nylas = Nylas::Client.new(api_key: 'API_KEY')
query_params = { limit: 5 }
messages, _ = nylas.messages.list(identifier: '<GRANT_ID>', query_params: query_params)

messages.each {|message|
 puts "[#{Time.at(message[:date]).strftime("%d/%m/%Y at %H:%M:%S")}] \
     #{message[:subject]}"
} 
from dotenv import load_dotenv
load_dotenv()

import os
import sys
from nylas import Client

nylas = Client(
   os.environ.get('NYLAS_API_KEY'),
   os.environ.get('NYLAS_API_URI')
)

grant_id = os.environ.get("NYLAS_GRANT_ID")

messages = nylas.messages.list(
 grant_id,
 query_params={
   "limit": 5
 }
)

print(messages)
import com.nylas.NylasClient;
import com.nylas.models.*;
import java.text.SimpleDateFormat;

public class ReadInbox {
 public static void main(String[] args) throws NylasSdkTimeoutError, NylasApiError {
   NylasClient nylas = new NylasClient.Builder("<NYLAS_API_KEY>").build();
   ListMessagesQueryParams queryParams = new ListMessagesQueryParams.Builder().limit(5).build();
   ListResponse<Message> message = nylas.messages().list("<GRANT_ID>", queryParams);

   for(Message email : message.getData()) {
     String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").
         format(new java.util.Date((email.getDate() * 1000L)));

     System.out.println("[" + date + "] | " + email.getSubject());
   }
 }
} 
curl --request GET \
  --url "https://api.us.nylas.com/v3/grants/NYLAS_GRANT_ID/messages?limit=5" \
  --header 'Accept: application/json' \
  --header 'Authorization: Bearer <NYLAS_API_KEY_OR_ACCESS_TOKEN>' \
  --header 'Content-Type: application/json'   
{
  "request_id": "d0c951b9-61db-4daa-ab19-cd44afeeabac",
  "data": [
      {
          "starred": false,
          "unread": true,
          "folders": [
              "UNREAD",
              "CATEGORY_PERSONAL",
              "INBOX"
          ],
          "grant_id": "1",
          "date": 1706811644,
          "attachments": [
              {
                  "id": "1",
                  "grant_id": "1",
                  "filename": "invite.ics",
                  "size": 2504,
                  "content_type": "text/calendar; charset=\"UTF-8\"; method=REQUEST"
              },
              {
                  "id": "2",
                  "grant_id": "1",
                  "filename": "invite.ics",
                  "size": 2504,
                  "content_type": "application/ics; name=\"invite.ics\"",
                  "is_inline": false,
                  "content_disposition": "attachment; filename=\"invite.ics\""
              }
          ],
          "from": [
              {
                  "name": "Nylas DevRel",
                  "email": "[email protected]"
              }
          ],
          "id": "1",
          "object": "message",
          "snippet": "Send Email with Nylas APIs",
          "subject": "Learn how to Send Email with Nylas APIs",
          "thread_id": "1",
          "to": [
              {
                  "name": "Nyla",
                  "email": "[email protected]"
              }
          ],
          "created_at": 1706811644,
          "body": "Learn how to send emails using the Nylas APIs!"
      }
  ],
  "next_cursor": "123"
}