activix / nylas-php
This package is abandoned and no longer maintained.
No replacement package was suggested.
PHP wrapper for the Nylas API (Adapted for Activix).
2.0.7
2023-06-13 15:00 UTC
Requires
- php: ^7.3|^8.0
- guzzlehttp/guzzle: ^7.0
README
Forked from nylas/nylas-php. Adapted for Activix.
PHP bindings for the Nylas REST API https://www.nylas.com.
Installation
You can install the library by running:
cd nylas-php composer install
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:
- You redirect the user to our login page, along with your App Id and Secret
- Your user logs in
- She is redirected to a callback URL of your own, along with an access code
- You use this access code to get an authorization token to the API
For more information about authenticating with Nylas, visit the Developer Documentation.
In practice, the Nylas REST API client simplifies this down to two steps.
Fetching Account Information
$client = new Nylas(CLIENT, SECRET, TOKEN); $account = $client->account(); echo $account->email_address; echo $account->provider;
Fetching Threads
$client = new Nylas(CLIENT, SECRET, TOKEN); // Fetch the first thread $firstThread = $client->threads()->first(); echo $firstThread->id; // Fetch first 2 latest threads $twoThreads = $client->threads()->all(2); foreach ($twoThreads as $thread) { echo $thread->id; } // List all threads with '[email protected]' $searchCriteria = ['any_email' => '[email protected]']; $getThreads = $client->threads()->where($searchCriteria)->items(); foreach ($getThreads as $thread) { echo $thread->id; }
Working with Threads
// List thread participants foreach ($thread->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 $toAdd = ['cfa1233ef123acd12']; $toRemove = ['inbox']; $thread->addTags($toAdd); $thread->removeTags($toRemove); // Listing messages foreach ($thread->messages()->items() as $message) { echo $message->subject; echo $message->body; }
Working with Files
$client = new Nylas(CLIENT, SECRET, TOKEN); $filePath = '/var/my/folder/test_file.pdf'; $uploadResp = $client->files()->create($filePath); echo $uploadResp->id;
Working with Drafts
$client = new Nylas(CLIENT, SECRET, TOKEN); $personObj = new \Nylas\Models\Person('Kartik Talwar', '[email protected]'); $messageObj = [ 'to' => [$personObj], 'subject' => 'Hello, PHP!', 'body' => 'Test <br> message' ]; $draft = $client->drafts()->create($messageObj); $sendMessage = $draft->send(); echo $sendMessage->id;
Working with Events
$client = new Nylas(CLIENT, SECRET, TOKEN); $calendars = $client->calendars()->all(); $calendar = null; foreach ($calendars as $i) { if (!$i->read_only) { $calendar = $i; } } $personObj = new \Nylas\Models\Person('Kartik Talwar', '[email protected]'); $calendarObj = [ 'title' => 'Important Meeting', 'location' => 'Nylas HQ', 'participants' => [$personObj], 'calendar_id' => $calendar->id, 'when' => [ 'start_time' => time(), 'end_time' => time() + (30 * 60), ], ]; // Create event $event = $client->events()->create($calendarObj); echo $event->id; // Update $event = $event->update(['location' => 'Meeting room #1']); // Delete event $event->delete(); // Delete event (alternate) $remove = $client->events()->find($event->id)->delete();