Syno

repository·master·Indexed 43 days ago

https://github.com/kwent/syno

A Node.js wrapper and CLI for the Synology DSM REST API (versions 6.x and 7.x). It provides programmatic access to Synology services including File Station, Download Station, Surveillance Station, Audio Station, Video Station, and Synology Photos. Version 3.0.3 requires Node.js >= 24.0.0 and uses native fetch.

Tokens
8.5K
Snippets
25
Records
39
Agent score
55%

What's inside Syno

  1. Understand Syno Station Aliases

    master

    The Syno API is organized into several service-specific classes, accessible via short aliases on the syno instance:

    Short AliasLong AliasClassService
    syno.dsmsyno.diskStationManagerDSMDSM
    syno.fssyno.fileStationFileStationFile Station
    syno.dlsyno.downloadStationDownloadStationDownload Station
    syno.assyno.audioStationAudioStationAudio Station
    syno.vssyno.videoStationVideoStationVideo Station
    syno.dtvsyno.videoStationDTVVideoStationDTVVideo Station DTV
    syno.sssyno.surveillanceStationSurveillanceStationSurveillance Station
    syno.photosyno.synologyPhotosSynologyPhotosSynology Photos (DSM 7.x only)
  2. Initialize the Syno client

    master

    To use the Syno API in JavaScript or TypeScript, import the Syno class and instantiate it with a configuration object. All API methods return Promises.

    import { Syno } from 'syno';
    
    const syno = new Syno({
        protocol: 'https',
        host: 'localhost',
        port: 5001,
        account: 'my_username',
        passwd: 'my_password',
        apiVersion: '7.2',
    });
    
    // Using a method directly
    const info = await syno.fs.getInfo();
    
    // Calling a method dynamically
    const info = await syno.fs.call('getInfo', { folder_path: '/path' });
    import { Syno } from 'syno';
    
    const syno = new Syno({
        protocol: 'https',
        host: 'localhost',
        port: 5001,
        account: 'my_username',
        passwd: 'my_password',
        apiVersion: '7.2',
    });
    
    const info = await syno.fs.getInfo();
  3. Migrate from Syno v2.x to v3.x

    master

    If you are upgrading from version 2.x, note the following breaking changes:

    • Async/await only: All methods now return Promises. Callbacks are no longer supported.
    • Node.js 24+ required: Uses native fetch.
    • Browser support removed: Node.js only.
    • Default API version: Changed from 6.0.2 to 7.2.
    • DSM 5.x support dropped: Only 6.x and 7.x definitions are included.
    • Module System: Supports both ESM (import) and CJS (require).
    • TypeScript: Types are included in the package; no separate @types package is needed.
  4. Install Syno via npm

    master

    To use Syno as a Node.js library in your project, install it via npm:

    npm install syno

    Requirements:

    • Node.js >= 24.0.0 (uses native fetch)

    To install the command-line interface (CLI) globally:

    npm install -g syno
  5. Understand the AuthenticatedAPI base class

    master

    The AuthenticatedAPI class is the base for all service-specific APIs in Syno that require authentication (e.g., DSM, File Station, Download Station). It manages session state automatically by checking for an existing session SID in the AuthenticatedAPIHost.

    If a valid session SID is found for the requested sessionName, it is automatically appended to the request parameters as _sid. If no session exists, the class performs an auto-login via this.syno.auth.login(sessionName), stores the resulting SID in the sessions map, and then proceeds with the original request.

  6. Access Synology Station modules

    master

    Syno uses a modular architecture where specific services are accessed via dedicated station classes. The following modules are exported and available through the client:

    • DSM: Core DSM functionality.
    • FileStation: File management and enumeration.
    • DownloadStation: Managing download tasks.
    • AudioStation: Audio management.
    • VideoStation: Video management.
    • VideoStationDTV: DTV-specific video features.
    • SurveillanceStation: Surveillance and camera management.
    • SynologyPhotos: Photo management and organization.
  7. Configure the Syno client

    master

    When instantiating new Syno(), you can provide the following configuration options:

    OptionTypeDefaultDescription
    accountstring-DSM user account (required)
    passwdstring-DSM user password (required)
    protocolstring'http''http' or 'https'
    hoststring'localhost'DSM hostname or IP
    portnumber5000DSM port
    apiVersionstring'7.2'DSM API version
    debugbooleanfalseEnable debug logging
    ignoreCertificateErrorsbooleanfalseIgnore TLS certificate errors
    otpCodestring-Two-factor auth OTP code
    sidstring-Reuse an existing session ID
    followRedirectsbooleantrueFollow HTTP redirects (QuickConnect)
  8. Manage the default configuration file

    master

    The project uses a default configuration directory and file to persist settings:

    • Directory: ~/.syno (in the user's home directory)
    • File: config.yaml

    Use ensureDefaultConfig() to automatically create this directory and a template config.yaml if they do not exist. This is useful for initializing a local environment for the CLI.

    import { ensureDefaultConfig } from '../src/cli/config.js';
    
    const configPath = ensureDefaultConfig();
    console.log(`Config is located at: ${configPath}`);
  9. Use the Syno CLI to interact with Synology APIs

    master

    The syno CLI allows you to execute Synology DSM API methods directly from your terminal. The command structure follows a pattern of syno <station> <method> [options].

    Each station corresponds to a specific Synology service (like File Station or Download Station). You must provide the name or alias of the station followed by the specific API method you wish to call.

    # Example: Calling a method on File Station
    syno fs list_folder --payload '{"path": "/volume1/homes"}'
    
    # Example: Using an alias for Download Station
    syno dl get_task_list
  10. Initialize the Syno client

    master

    The Syno class is the primary entrypoint for interacting with Synology NAS services. You initialize it by passing a SynoConfig object to the constructor. The client supports configuration via both the config object and environment variables.

    Configuration Options

    KeyEnv VarDefaultDescription
    accountSYNO_ACCOUNTRequiredSynology username
    passwdSYNO_PASSWORDRequiredSynology password
    hostSYNO_HOSTlocalhostThe hostname or IP of the NAS
    portSYNO_PORT5000The port for the API
    protocolSYNO_PROTOCOLhttphttp or https
    apiVersionSYNO_API_VERSION7.2The target DSM API version
    debugSYNO_DEBUGfalseEnables debug logging to console
    ignoreCertificateErrorsSYNO_IGNORE_CERTIFICATE_ERRORSfalseBypasses TLS certificate validation (useful for self-signed certs)
    sidN/AN/AA pre-existing session ID to reuse existing sessions
    otpCodeN/AN/AOne-time password code if 2FA is enabled
    followRedirectsN/AtrueWhether to follow HTTP redirects

    Session Reuse

    If you provide a sid in the configuration, the client will pre-populate sessions for all major stations (DSM, FileStation, DownloadStation, etc.), allowing you to bypass the initial login flow.

    import { Syno } from 'kwent/kwent/syno';
    
    const syno = new Syno({
      account: 'admin',
      passwd: 'your-password',
      host: '192.168.1.100',
      port: 5001,
      protocol: 'https',
      ignoreCertificateErrors: true
    });
  11. Troubleshoot TLS certificate errors

    master

    If you encounter Error: UNABLE_TO_VERIFY_LEAF_SIGNATURE when using https, you can bypass certificate verification using one of these methods:

    CLI Flag:

    syno fs getInfo --ignore-certificate-errors

    Environment Variable:

    export SYNO_IGNORE_CERTIFICATE_ERRORS=1

    Code Configuration:

    const syno = new Syno({
        ignoreCertificateErrors: true,
        // ...
    });
  12. Configure Syno via environment variables

    master

    You can override connection settings and behavior using the following environment variables. These take precedence over configuration files but are overridden by explicit CLI options.

    Environment VariableDescription
    SYNO_PROTOCOLConnection protocol (http or https)
    SYNO_HOSTSynology NAS hostname or IP
    SYNO_PORTConnection port
    SYNO_ACCOUNTUsername
    SYNO_PASSWORDPassword
    SYNO_API_VERSIONTarget DSM API version
    SYNO_DEBUGEnable debug mode (truthy values)
    SYNO_IGNORE_CERTIFICATE_ERRORSIgnore SSL certificate errors (truthy values)