Only show these results:

Authorizing API Requests

Once you've successfully connected an email account using one of the authentication methods, you'll have an <ACCESS_TOKEN> that allows you to pull email, contact, and calendar data for that email account. This article will cover each authentication method using the <ACCESS_TOKEN>.

Bearer Authentication

Bearer authentication requires the <ACCESS_TOKEN> for authentication.

curl -X GET -H 'Authorization: Bearer <ACCESS_TOKEN>' 'https://api.nylas.com/account'   

Basic Authentication

You can use basic authentication for every Nylas endpoint. Basic authentication requires the <CLIENT_ID:CLIENT_SECRET>
to be base 64 encoded.

curl -X GET -H 'Authorization: Basic <CLIENT_ID:CLIENT_SECRET>' 'https://api.nylas.com/account'   

Client ID and Client Secret

A few endpoints require you to use the <CLIENT_SECRET> as the basic authentication username with the password field left blank. The <CLIENT_SECRET> needs to be base64 encoded.

curl -X GET -H 'Authorization: Basic <CLIENT_SECRET>' 'https://api.nylas.com/a/{client_id}/accounts/'   

These are endpoints that use the <CLIENT_SECRET>:

Base64 Encode

You can encode the <CLIENT_SECRET> or the <ACCESS_TOKEN> usingecho -n "username:password" | base64. The username is the <CLIENT_SECRET> or <ACCESS_TOKEN> and the password is blank and not included.

$ echo ‘d57963d558d1:b35592e51016’ | base64
4oCYZDU3OTYzZDU1OGQxOmIzNTU5MmU1MTAxNuKAmQo=

Then replace the <CLIENT_SECRET> and <ACCESS_TOKEN> with the base64 string that is returned when making API requests.

Deciding Which to Use

Each endpoint includes a list of the authentication types. In general, we recommend you use Bearer Authentication.

SDK Authentication

SDK's require you to have the <CLIENT_ID>, <CLIENT_SECRET> and <ACCESS_TOKEN> passed in. Store these as environment variables.

  require 'nylas'

nylas = Nylas::API.new(
app_id: '<CLIENT_ID>',
app_secret: '<CLIENT_SECRET>',
access_token: '<ACCESS_TOKEN>')
# Access tokens should be secured securely in your database.

# Print the user account
puts nylas.current_account
  const Nylas = require('nylas');

Nylas.config({
appId: '<CLIENT_ID>',
appSecret: '<CLIENT_SECRET>',
});

const nylas = Nylas.with('<ACCESS_TOKEN>');
// Access tokens should be secured securely in your database.

// Print the user account
nylas.account.get().then(account => console.log(account));
  from nylas import APIClient

nylas = APIClient(
'<CLIENT_ID>',
'<CLIENT_SECRET>',
'<ACCESS_TOKEN>'
)
# Access tokens should be secured securely in your database.

# Print the user account
print(nylas.account)