PHP code example of gostellarco / nylas-php

1. Go to this page and download the library: Download gostellarco/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/ */

    

gostellarco / nylas-php example snippets


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',        // 

$nylas->Options()->

$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);

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

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

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

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

   [
       'httpStatus'  => 'http status code',
       'invalidJson' => true,
       'contentType' => 'response header content type',
       'contentBody' => 'response body content',
   ]
   

   [
       // ...
       [
           'error'     => true,
           'code'      => 'exception code',
           'message'   => 'exception message',
           'exception' => 'exception instance',
       ],
       // ...
   ]
   

   $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);
   

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

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

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

$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);

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

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

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

$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);

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

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

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

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

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

$nylas->Webhooks()->Webhook()->xxx();
shell
composer