PHP code example of sejongtf / synology
1. Go to this page and download the library: Download sejongtf/synology 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/ */
sejongtf / synology example snippets
$syno = Synology::withSession('https://nas:5001', $sid);
$syno->contacts->contact->list(['addressbook_id' => 1]);
$syno->chat->channel->list();
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\HttpFactory;
$syno = Synology::withSession($url, $sid, new Client, new HttpFactory);
$syno = Synology::withSession($url, $sid, $http, $requestFactory, $streamFactory);
$syno = Synology::withSession($url, $sid);
$syno = Synology::withSession($url, new Session($sid, synoToken: $token));
use Sejongtf\Synology\Auth\CallableStore;
$syno = Synology::withStore($url, new CallableStore(
get: fn () => $cache->get('syno.session'), // Session | array | sid string | null
put: fn (Session $s) => $cache->set('syno.session', $s->toArray()),
));
$syno = Synology::connect($url, 'user', 'pass', otpCode: '123456');
try {
$syno->contacts->contact->list(['addressbook_id' => 1]);
} catch (AuthException $e) {
if ($e->
$syno = Synology::connect($url, 'user', 'pass',
otpCode: '123456',
rememberDevice: true,
store: $store, // sid and did both land in this store
);
use Closure;
use Sejongtf\Synology\Auth\Authenticator;
$syno = Synology::to($url)
->credentials('user', 'pass')
->store($shared)
// (1) cold start — the store is empty and somebody has to log in
->onLogin(fn (Closure $login) => $lock->block(5, fn () => $shared->get() ?? $login()))
// (2) the session died mid-flight (106/107/119)
->onSessionExpired(fn (string $staleSid, Authenticator $auth) => $lock->block(5, function () use ($staleSid, $auth, $shared) {
$current = $shared->get();
return $current && $current->sid !== $staleSid ? $current : $auth->refresh();
}))
->connect();
$syno->mail_account->mail->send([...]);
$syno->mailAccount->mail->send([...]); // the same
$syno->chat->channel->list(); // magic call
$syno->contacts->contact->get([1, 2, 3]); // hand-written signature
$syno->chat->external->incoming($token, 'Hello');
$data = $syno->calendar->event->list([...]); // array|null
$response = $syno->chat->post->raw('list', params: [...]);
$response->success();
$response->hasData();
$response->header('Content-Type');
$response->toPsrResponse()->getBody(); // binary goes through here
use Sejongtf\Synology\Exceptions\ApiException;
use Sejongtf\Synology\Exceptions\AuthException;
$syno->contacts->contact->list(['addressbook_id' => 1]); // null on failure
try {
$data = $syno->contacts->contact
->raw('list', params: ['addressbook_id' => 1])
->throw()
->data();
} catch (AuthException $e) {
// login failure, 2FA
$syno->chat->channel->request('list', version: 5, params: [...]);
$syno->discover(); // everything
$syno->discover('SYNO.Chat.Channel');
$registry = $syno->discover('SYNO.Chat.Channel');
$registry->maxVersion('SYNO.Chat.Channel'); // the highest version this NAS advertises
$registry->path('SYNO.Chat.Channel'); // the real path
bash
composer