Skip to content

Using the Kotlin/Java SDK

As of August 2023, Nylas offers a Kotlin/Java SDK as part of Nylas v3, in addition to the legacy Java-only v2.7 SDK.

The v2.x Kotlin/Java SDK is only compatible with v3.x Nylas APIs. If you’re still using an earlier version of Nylas, you should keep using the v1.x Java SDK until you can upgrade to Nylas v3.

Before you can start using the Nylas Kotlin/Java SDK, make sure you have done the following:

Note: The Nylas Kotlin/Java SDK requires Java 8 or later.

For the following examples, replace X.X.X with the version you want to use. See the list of Kotlin/Java SDK releases to learn about the available versions.

If you’re using Gradle, add the following code to the dependencies section of your build.gradle file. Be sure to use only the code that matches the SDK version you want to use.

For projects using Maven, add the following code to your POM file.

<dependency>
<groupId>com.nylas.sdk</groupId>
<artifactId>nylas</artifactId>
<version>X.X.X</version>
</dependency>

To start using the Kotlin/Java SDK, you must initialize the NylasClient object. The Nylas client allows you to access the Manage Grants endpoints.

To create a Nylas application client object, initialize a NylasClient object and pass in your Nylas application’s API key and API URI.

Be careful with secrets! Follow best practices when you include secrets like your access token in your code. A more secure way to provide these values is to use a KeyStore to protect sensitive information.

Now that you have the Kotlin/Java SDK installed and set up, you can make a simple program to test your installation. For example, the following code makes a request to return information about your Nylas application.

The Nylas APIs use OAuth 2.0 and let you choose to authenticate using either an API key or access token. For more information about authenticating with Nylas, see the Authentication guide.

In practice, Nylas’ REST API simplifies the OAuth process to two steps: redirecting the user to Nylas, and handling the auth response.

The following code samples redirect a user to Nylas for authentication.

Nylas provides granular scopes that allow you to control the level of access your application has to users’ data. For a list of scopes that Nylas supports, see Using granular scopes to request user data.

Next, your application has to handle the authentication response from Nylas, as in the examples below.

For the latest supported version of the SDK, see the Releases page on GitHub.

The Nylas Kotlin/Java SDK includes method and model documentation, so you can easily find the implementation details you need.

The Nylas Kotlin/Java SDK repository houses the Kotlin/Java SDK and a number of useful tutorials that demonstrate how to handle things like webhooks, Bring Your Own Authentication, and Hosted OAuth. You can contribute to the SDK by creating an issue or opening a pull request.

For code samples, visit the Nylas Samples repository.