PHP code example of activix / nylas-php
1. Go to this page and download the library: Download activix/nylas-php library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
activix / nylas-php example snippets
cd nylas-php
composer install
$client = new Nylas(CLIENT, SECRET, TOKEN);
$account = $client->account();
echo $account->email_address;
echo $account->provider;
$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;
}
// 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;
}
$client = new Nylas(CLIENT, SECRET, TOKEN);
$filePath = '/var/my/folder/test_file.pdf';
$uploadResp = $client->files()->create($filePath);
echo $uploadResp->id;
$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;
$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();