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.

Before you begin

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

Install the Nylas Kotlin/Java SDK

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.

Set up with Gradle

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.

Set up with Maven

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>

Initialize the Nylas Client

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.

Test Kotlin/Java SDK installation

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.

Authenticate end users

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 end user to Nylas, and handling the auth response.

Redirect end user to Nylas

The following code samples redirect an end user to Nylas for authentication.

Handle the authentication response

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

Latest supported version

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

Method and model reference

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

GitHub repositories

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, Custom 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.

Tutorials