PHPackages                             nylas/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. [API Development](/categories/api)
4. /
5. nylas/nylas-php

ActiveLibrary[API Development](/categories/api)

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

PHP wrapper for the Nylas API

191.1k25[5 PRs](https://github.com/nylas/nylas-php/pulls)PHPCI failing

Since Feb 5Pushed 8y ago10 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Nylas PHP
---------

[](#nylas-php)

PHP bindings for the Nylas REST API

**NOTE**: The Nylas PHP SDK is currently not actively maintained, and may need some TLC. However, our [Ruby](https://github.com/nylas/nylas-ruby), [Node](https://github.com/nylas/nylas-nodejs) or [Python](https://github.com/nylas/nylas-python) SDKs are fully supported.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#note-the-nylas-php-sdk-is-currently-not-actively-maintained-and-may-need-some-tlc-however-our-ruby-node-or-python-sdks-are-fully-supported)

Please feel free to use it and send us a pull request if you fix anything or add a feature, though. :)

Installation
------------

[](#installation)

You can install the library by running:

```
cd nylas-php
composer install
```

Usage
-----

[](#usage)

The Nylas REST API uses server-side (three-legged) OAuth, and this library provides convenience methods to simplify the OAuth process. Here's how it works:

1. You redirect the user to our 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://www.nylas.com/docs/gettingstarted-hosted#authenticating).

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

Auth
----

[](#auth)

**index.php**

```
$client = new Nylas(CLIENT, SECRET);
$redirect_url = 'http://localhost:8080/login_callback.php';
$get_auth_url = $client->createAuthURL($redirect_url);

// redirect to Nylas auth server
header("Location: ".$get_auth_url);
```

**login\_callback.php**

```
$access_code = $_GET['code'];
$client = new Nylas(CLIENT, SECRET);
$get_token = $client->getAuthToken($access_code);

// save token in session
$_SESSION['access_token'] = $get_token;
```

Fetching Account Information
----------------------------

[](#fetching-account-information)

```
$client = new Nylas(CLIENT, SECRET, TOKEN);
$account = $client->account();

echo $account->email_address;
echo $account->provider;
```

Fetching Threads
----------------

[](#fetching-threads)

```
$client = new Nylas(CLIENT, SECRET, TOKEN);

// Fetch the first thread
$first_thread = $client->threads()->first();
echo $first_thread->id;

// Fetch first 2 latest threads
$two_threads = $client->threads()->all(2);
foreach($two_threads as $thread) {
    echo $thread->id;
}

// List all threads with 'ben@nylas.com'
$search_criteria = array("any_email" => "ben@nylas.com");
$get_threads = $client->threads()->where($search_criteria)->items()
foreach($get_threads as $thread) {
    echo $thread->id;
}
```

Working with Threads
--------------------

[](#working-with-threads)

```
// List thread participants
foreach($thead->participants as $participant) {
    echo $participant->email;
    echo $participant->name;
}

// Mark as Read
$thread->markAsRead();

// Mark as Seen
$thread->markAsSeen();

// Archive
$thread->archive();

// Unarchive
$thread->unarchive();

// Trash
$thread->trash();

// Star
$thread->star();

// Unstar
$thread->unstar();

// Add or remove arbitrary tags
$to_add = array('cfa1233ef123acd12');
$to_remove = array('inbox');
$thread->addTags($to_add);
$thread->removeTags($to_remove);

// Listing messages
foreach($thread->messages()->items() as $message) {
    echo $message->subject;
    echo $message->body;
}
```

Working with Files
------------------

[](#working-with-files)

```
$client = new Nylas(CLIENT, SECRET, TOKEN);

$file_path = '/var/my/folder/test_file.pdf';
$upload_resp = $client->files()->create($file_path);
echo $upload_resp->id;
```

Working with Drafts
-------------------

[](#working-with-drafts)

```
$client = new Nylas(CLIENT, SECRET, TOKEN);

$person_obj = new \Nylas\Models\Person('Kartik Talwar', 'kartik@nylas.com');
$message_obj = array( "to" => array($person_obj),
                      "subject" => "Hello, PHP!",
                      "body" => "Test  message");

$draft = $client->drafts()->create($message_obj);
$send_message = $draft->send();
echo $send_message->id;
```

Working with Events
-------------------

[](#working-with-events)

```
$client = new Nylas(CLIENT, SECRET, TOKEN);
$calendars = $client->calendars()->all();

$calendar = null;
foeach($calendars as $i) {
  if(!$i->read_only) {
    $calendar = $i;
  }
}

$person_obj = new \Nylas\Models\Person('Kartik Talwar', 'kartik@nylas.com');
$calendar_obj = array("title" => "Important Meeting",
                      "location" => "Nylas HQ",
                      "participants" => array($person_obj),
                      "calendar_id" => $calendar->id,
                      "when" => array("start_time" => time(),
                                      "end_time" => time() + (30*60)));
// create event
$event = $client->events()->create($calendar_obj);
echo $event->id;

// update
$event = $event->update(array("location" => "Meeting room #1"));

// delete event
$event->delete();
// delete event (alternate)
$remove = $client->events()->find($event->id)->delete();
```

Open-Source Sync Engine
-----------------------

[](#open-source-sync-engine)

The [Nylas Sync Engine](http://github.com/nylas/sync-engine) is open-source, and you can also use the PHP library with the open-source API. Since the open-source API provides no authentication or security, connecting to it is simple. When you instantiate the Nylas object, provide null for the App ID, App Secret, and API Token, and pass the fully-qualified address of your copy of the sync engine:

```
$client = new Nylas(CLIENT, SECRET, TOKEN, 'http://localhost:5555/');
```

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

[](#contributing)

We'd love your help making Nylas better. Join the Google Group for project updates and feature discussion. We also hang out in `#nylas` on [irc.freenode.net](irc.freenode.net), or you can email .

Please sign the Contributor License Agreement before submitting pull requests. (It's similar to other projects, like NodeJS or Meteor.)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.7% 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.

### Community

Maintainers

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

---

Top Contributors

[![KartikTalwar](https://avatars.githubusercontent.com/u/461702?v=4)](https://github.com/KartikTalwar "KartikTalwar (36 commits)")[![khamidou](https://avatars.githubusercontent.com/u/44081?v=4)](https://github.com/khamidou "khamidou (2 commits)")

### Embed Badge

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

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

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[facebook/php-business-sdk

PHP SDK for Facebook Business

90821.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

74513.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

265103.1M454](/packages/google-gax)[google/common-protos

Google API Common Protos for PHP

173103.7M50](/packages/google-common-protos)

PHPackages © 2026

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