PHPackages                             gostellarco/nylas-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. gostellarco/nylas-php

ActiveLibrary

gostellarco/nylas-php
=====================

Nylas PHP SDK (api version 2.1)

4.2.5(5y ago)06MITPHPPHP &gt;=7.4

Since Dec 4Pushed 4y agoCompare

[ Source](https://github.com/gostellarco/nylas-php)[ Packagist](https://packagist.org/packages/gostellarco/nylas-php)[ RSS](/packages/gostellarco-nylas-php/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependencies (4)Versions (33)Used By (0)

 [![](media/nylas-php.png)](media/nylas-php.png)

Nylas PHP SDK
=============

[](#nylas-php-sdk)

[![Build](https://github.com/lanlin/nylas-php/workflows/Testing/badge.svg?branch=master)](https://github.com/lanlin/nylas-php/actions)[![Code Quality](https://github.com/lanlin/nylas-php/workflows/CodeQuality/badge.svg?branch=master)](https://github.com/lanlin/nylas-php/actions)[![Packagist Version (including pre-releases)](https://camo.githubusercontent.com/d0e9d629ef3e04535a063bbbdccd765c67ee212e243ce77a0f366157b8df2e64/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c616e6c696e2f6e796c61732d7068703f696e636c7564655f70726572656c6561736573)](https://packagist.org/packages/lanlin/nylas-php)[![Packagist Stars](https://camo.githubusercontent.com/898084c28342aba57966a48cb270333ee2fc92ef8766556e7ce5fffedd916d81/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f73746172732f6c616e6c696e2f6e796c61732d706870)](https://packagist.org/packages/lanlin/nylas-php)[![Total Downloads](https://camo.githubusercontent.com/d1e7083a303180cf408b215b69f0e9544840c4d3b695b65c960e98017b98c151/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c616e6c696e2f6e796c61732d706870)](https://packagist.org/packages/lanlin/nylas-php)[![Packagist PHP Version Support](https://camo.githubusercontent.com/3ca7ee32bad31a04deb7e892a0d951f927f3182a964bbdf0294e96665886b891/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6c616e6c696e2f6e796c61732d706870)](https://packagist.org/packages/lanlin/nylas-php)[![License](https://camo.githubusercontent.com/499536b5e4682c46900296ca297e3d0aeebb4f2980f3d808451de635be560035/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6c616e6c696e2f6e796c61732d706870)](https://github.com/lanlin/nylas-php#license)

PHP bindings for the Nylas REST API (V2.1).
I'll try to keep up with [NyLas Changelog](https://changelog.nylas.com) in future updates.

Last check at the point: [Dashboard Release for Canada and Ireland](https://changelog.nylas.com/#entry-176451)

**What's new?**

1. API 2.1 support
2. All Nylas APIs have been implemented within this SDK.
3. Support send &amp; get message in raw type
4. Support async batch upload &amp; download
    -- Contact picture download
    -- File upload &amp; download
5. The parameters that required by methods almost the same as nylas official api required.
6. Support async batch get &amp; delete &amp; send (since version 3.1).
7. Chained calls and good code hints, easy to use

 [![](media/autocomplete.gif)](media/autocomplete.gif)

Installation (PHP 7.4 required since version 4.0)
-------------------------------------------------

[](#installation-php-74-required-since-version-40)

**version 3.x for php &gt;= 7.3 (branch 3.0)**

**version 4.x for php &gt;= 7.4 (branch master)**

This library is available on
You can install it by running

```
composer require lanlin/nylas-php
```

Usage
-----

[](#usage)

### App ID and Secret

[](#app-id-and-secret)

Before you can interact with the Nylas REST API,
you need to create a Nylas developer account at .
After you've created a developer account, you can create a new application to generate an App ID / Secret pair.

Generally, you should store your App ID and Secret into environment variables to avoid adding them to source control.
The test projects use configuration files instead, to make it easier to get started.

### Init Nylas-PHP

[](#init-nylas-php)

*TIPS:* 'off\_decode\_error' has removed since version 4.1.2, see [Error &amp; Exceptions](#error--exceptions)

```
use Nylas\Client;

$options =
[
    'debug'            => true,
    'region'           => 'oregon',   // server region, can be oregon, ireland or canada, default is oregon
    'log_file'         => dirname(__FILE__) . '/test.log',  // a file path or a resource handler
    'account_id'       => 'your account id',
    'access_token'     => 'your access token',

    'client_id'        => 'your client id',        // required
    'client_secret'    => 'your client secret'     // required
];

$nylas = new Client($options);
```

### Options Setting

[](#options-setting)

You can modify options with these methods:

```
$nylas->Options()->
```

 [![](media/options.png)](media/options.png)

### Batch Request

[](#batch-request)

Most of the methods that have the get &amp; delete prefix support batch request.

```
$id  = 'id_xxx';
$ids = ['id_xxx', 'id_yyy', ...];

// one per time
$dataA = $nylas->Contacts()->Contact()->getContact($id);
$dataB = $nylas->Contacts()->Contact()->deleteContact($id);

// batch request
$dataC = $nylas->Contacts()->Contact()->getContact($ids);
$dataD = $nylas->Contacts()->Contact()->deleteContact($ids);
```

For more detail about the batch request, you should have to read the source code.
Sorry, I have no time to write documents.

### Authentication

[](#authentication)

There are two ways you can authenticate users to your application.
Hosted &amp; Native are both supported.

Here's the server-side(three-legged) OAuth example:

1. You redirect the user to nylas login page, along with your App Id and Secret
2. Your user logs in
3. She is redirected to a callback URL of your own, along with an access code
4. You use this access code to get an authorization token to the API

For more information about authenticating with Nylas,
visit the [Developer Documentation](https://docs.nylas.com/reference#authentication).

In practice, the Nylas REST API client simplifies this down to two steps.

**Step 1: Redirect the user to Nylas:**

```
$params =
[
    'state'        => 'testing',
    'login_hint'   => 'test@gmail.com',
    'redirect_uri' => 'https://www.test.com/redirect_callback',
];

// generate the url that your user need be redirect to.
$url = $nylas->Authentication()->Hosted()->getOAuthAuthorizeUrl($params);
```

**Step 2: your user logs in:**
**Step 3: you got the access code from the nylas callback:**
Please implement the above 2 &amp; 3 steps yourself.

**Step 4: Get authorization token with access code:**

```
$data = $nylas->Authentication()->Hosted()->postOAuthToken($params);

// save your token some where
// or update the client option
$nylas->Options()->setAccessToken("pass the token you got");
```

Error &amp; Exceptions
----------------------

[](#error--exceptions)

1. common error codes that response from nylas are wrapped as exceptions, (see `src/Exceptions`) and the exception code is the same as [nylas api error list](https://docs.nylas.com/reference#errors)
2. you will get an array like below, when response data was not a valid json string or even not json content type:

    ```
    [
        'httpStatus'  => 'http status code',
        'invalidJson' => true,
        'contentType' => 'response header content type',
        'contentBody' => 'response body content',
    ]
    ```
3. for all methods that execute as the async mode will not throw an exception when an error occurs, instead, it will return an array which contains all data and exceptions inside like below:

    ```
    [
        // ...
        [
            'error'     => true,
            'code'      => 'exception code',
            'message'   => 'exception message',
            'exception' => 'exception instance',
        ],
        // ...
    ]
    ```
4. some email provider may not support all features, exp: calendar, event. for that reason you may get an exception named `BadRequestException` with 400 code and the msg:

    ```
    Malformed or missing a required parameter, or your email provider not support this.
    ```
5. the `log_file` parameter only works when `debug` set to `true`, then the detailed info of the http request will be logged.

    Tips: nylas-php use the guzzlehttp for http request. but guzzlehttp only support a resource type as the debug handler (cURL CURLOPT\_STDERR required that).

    for anyone who wants to use psr/log interface to debug, you can init a temp resource, and pass the handler to nylas-php, then get log content from temp resource after calling some methods.

    ```
    $handler = fopen('php://temp', 'w+');

    $options =
    [
        'log_file' => $handler,
        ...
    ];

    $nylas = new Client($options);
    $nylas->doSomething();
    ....

    rewind($handler);
    $logContent = stream_get_contents($handler);
    fclose($handler);

    $yourPsrLogger->debug($logContent);
    ```

Launching the tests
-------------------

[](#launching-the-tests)

1. Initialise composer dependency `composer install`
2. Add your info in `tests/AbsCase.php`
3. Launch the test with `composer run-script test`
4. Another way to run tests: `./tests/do.sh foo.php --filter fooMethod`, see `tests/do.sh`

Supported Methods
-----------------

[](#supported-methods)

The parameters that required by methods almost the same as nylas official api required.

For more detail, you can view the tests or the source code of validation rules for that method.

### [Accounts](https://docs.nylas.com/reference#accounts)

[](#accounts)

```
$nylas->Accounts()->Account()->xxx();
$nylas->Accounts()->Manage()->xxx();
```

### [Authentication](https://docs.nylas.com/reference#authentication)

[](#authentication-1)

```
$nylas->Authentication()->Hosted()->xxx();
$nylas->Authentication()->Native()->xxx();
```

### [Calendars](https://docs.nylas.com/reference#calendars)

[](#calendars)

```
$nylas->Calendars()->Calendar()->xxx();
```

### [Contacts](https://docs.nylas.com/reference#contacts-intro)

[](#contacts)

```
$nylas->Contacts()->Contact()->xxx();
```

```
// multiple contact pictures download
$params =
[
    [
        'id'   => 'contact id',
        'path' => 'this can be a file path, resource or stream handle',
    ],
    [
        'id'   => 'xxxx',
        'path' => dirname(__FILE__) . '/correct.png',
    ],
    // ...
];

$nylas->Contacts()->Contact()->getContactPicture($params);
```

### [Deltas](https://docs.nylas.com/reference#deltas)

[](#deltas)

```
$nylas->Deltas()->Delta()->xxx();
```

### [Draft](https://docs.nylas.com/reference#drafts)

[](#draft)

```
$nylas->Drafts()->Draft()->xxx();
$nylas->Drafts()->Sending()->xxx();
```

### [Events](https://docs.nylas.com/reference#events)

[](#events)

```
$nylas->Events()->Event()->xxx();
```

### [Files](https://docs.nylas.com/reference#files)

[](#files)

```
$nylas->Files()->File()->xxx();
```

```
// multiple files download
$params =
[
    [
        'id'   => 'file id',
        'path' => 'this can be a file path, resource or stream handle',
    ],
    [
        'id'   => 'xxxx',
        'path' => dirname(__FILE__) . '/correct.png',
    ],
    // ...
];

$nylas->Files()->File()->downloadFile($params);

// multiple files upload
$params =
[
    [
        'contents' => 'this can be a file path, resource or stream handle',
        'filename' => 'your file name'
    ],
    [
        'contents' => dirname(__FILE__) . '/correct.png',
        'filename' => 'test_correct.png'
    ],
    // ...
];

$nylas->Files()->File()->uploadFile($params);
```

### [Folders](https://docs.nylas.com/reference#folders)

[](#folders)

```
$nylas->Folders()->Folder()->xxx();
```

### [Labels](https://docs.nylas.com/reference#labels)

[](#labels)

```
$nylas->Labels()->Label()->xxx();
```

### [Job-Statuses](https://docs.nylas.com/reference#job-statuses)

[](#job-statuses)

```
$nylas->JobStatuses()->JobStatus()->xxx();
```

### [Messages](https://docs.nylas.com/reference#messages)

[](#messages)

```
$nylas->Messages()->Message()->xxx();
$nylas->Messages()->Search()->xxx();
$nylas->Messages()->Sending()->xxx();
$nylas->Messages()->Smart()->xxx();
```

### [Threads](https://docs.nylas.com/reference#threads)

[](#threads)

```
$nylas->Threads()->Search()->xxx();
$nylas->Threads()->Thread()->xxx();
$nylas->Threads()->Smart()->xxx();
```

### [Webhooks](https://docs.nylas.com/reference#webhooks)

[](#webhooks)

```
$nylas->Webhooks()->Webhook()->xxx();
```

Contributing
------------

[](#contributing)

For more usage demos, please view the tests.
Please feel free to use it and send me a pull request if you fix anything or add a feature, though.

License
-------

[](#license)

This project is licensed under the MIT license.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 89.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~28 days

Recently: every ~13 days

Total

32

Last Release

1831d ago

Major Versions

3.7.0 → 4.2.12020-09-30

3.7.1 → 4.2.22020-11-17

3.7.2 → 4.2.32020-12-08

3.7.3 → 4.2.42021-03-19

3.7.4 → 4.2.52021-05-11

PHP version history (3 changes)3.0.0PHP &gt;=7.0

4.0.0PHP &gt;=7.4

3.6.0PHP &gt;=7.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/aa73789bfa4b6cc8e6cb4b2a1bb19dc40656b38e177c75d2a8483a3b89b46a7c?d=identicon)[goranZic](/maintainers/goranZic)

---

Top Contributors

[![lanlin](https://avatars.githubusercontent.com/u/3468024?v=4)](https://github.com/lanlin "lanlin (188 commits)")[![jeremygriffin](https://avatars.githubusercontent.com/u/14842024?v=4)](https://github.com/jeremygriffin "jeremygriffin (13 commits)")[![GoranZic](https://avatars.githubusercontent.com/u/821625?v=4)](https://github.com/GoranZic "GoranZic (4 commits)")[![ChrisThompsonTLDR](https://avatars.githubusercontent.com/u/348801?v=4)](https://github.com/ChrisThompsonTLDR "ChrisThompsonTLDR (3 commits)")[![Grummfy](https://avatars.githubusercontent.com/u/668804?v=4)](https://github.com/Grummfy "Grummfy (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/gostellarco-nylas-php/health.svg)

```
[![Health](https://phpackages.com/badges/gostellarco-nylas-php/health.svg)](https://phpackages.com/packages/gostellarco-nylas-php)
```

###  Alternatives

[neuron-core/neuron-ai

The PHP Agentic Framework.

1.8k245.3k21](/packages/neuron-core-neuron-ai)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[lanlin/nylas-php

Nylas PHP SDK (api version 2.7)

28258.7k](/packages/lanlin-nylas-php)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
