App API reference
A native app has one Go backend; its UI calls named methods such as greeting.get.
Call format
Section titled “Call format”ctx.call(method, params) sends a same-origin JSON POST with the user’s DSM session.
| Part | Value |
|---|---|
| Request body | {"method": "app.status", "params": {}}. Unknown fields are refused. |
| Success | {"success": true, "data": …}. ctx.call resolves with data. |
| Error | {"success": false, "error": {"code": "…", "message": "…"}}. ctx.call rejects with {code, message}. |
| HTTP status | Always 200, so DSM does not replace the body. |
| Origin | Same origin only; Content-Type must be application/json. |
Codes: Error codes. Upload and download use a query-string method (?method=nas.files.upload, ?method=nas.files.download) instead; the helpers handle it.
Permissions
Section titled “Permissions”Each method has one level, set outside the handler in backend/internal/api/permissions.json.
| Level | Who can call |
|---|---|
administrators | Members of the DSM administrators group. This is the default. |
authenticated | Any signed-in DSM user who passes the entry check. |
public | Anyone. No sign-in. Only the identity.* methods use it. |
An unlisted method is administrators: a non-administrator gets admin_required, and an unregistered method gives unknown_method.
{ "schema": 1, "default": "administrators", "methods": { "app.status": "authenticated", "reports.list": "authenticated" }}| Rule | Value |
|---|---|
| File shape | Exactly schema, default and methods; default is administrators. |
| Method names | Lowercase area.action, such as reports.list. Pattern ^[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*)+$, at most 128 characters. |
| Size | At most 1024 methods and 64 KiB; duplicate keys are refused. |
| Registered methods | Every listed method needs a handler. |
| Capability methods | Fixed for nas.*, bg.*, identity.*, portal.*, executor.*, root.run and delegate.*. |
check and build validate the file; errors use STANDALONE_API_PERMISSIONS_INVALID.
Entry gate
Section titled “Entry gate”The entry field of dsm-package.yaml limits who can open the app; administrators always pass and public methods skip it (Manifest reference).
entry | Effect |
|---|---|
| Omitted | No extra check. Any user who can open the window can call authenticated methods. |
admin-only | Only administrators; others get admin_required. |
app-privilege | Only users DSM Application Privileges allow; others get app_privilege_denied. Needs at least one method that is not administrators; files or jobs suffice. |
Built-in methods
Section titled “Built-in methods”Add a capability with synopkgland add <name> or init --with <name>.
Base template
Section titled “Base template”| Method | Permission | Purpose |
|---|---|---|
app.status | administrators | Package name, version, caller (user, admin), process, platform and time. |
greeting.get | administrators | Reads the example greeting. Returns {text}. |
greeting.set | administrators | Writes the example greeting. {text} must be 1 to 200 characters. |
These three are examples; replace them. init --with delegate also lists app.status as authenticated.
Files (files)
Section titled “Files (files)”| Method | Permission | Params | Purpose |
|---|---|---|---|
nas.session.status | authenticated | none | Returns {mode: "filestation-session"} when file access is on. |
nas.files.shares | authenticated | offset | Lists Shared Folders the user can see. |
nas.files.list | authenticated | path, offset, limit (at most 100), sortBy (name, size, type, mtime), sortDirection (ASC, DESC) | Lists a folder. |
nas.files.info | authenticated | path | Returns one file or folder. |
nas.files.create_folder | authenticated | parent, name | Creates a folder. Returns {created: true}. |
nas.files.upload | authenticated | Query parent, name. Body is the file. | Uploads a file; never overwrites and never creates the parent. Needs Content-Length, at most 16 GiB. |
nas.files.download | authenticated | Query path | Downloads a file as an attachment. |
Calls run with the user’s own DSM permissions (Files). Paths are absolute, at most 4096 characters, without \, ,, " or control characters.
Background jobs (jobs)
Section titled “Background jobs (jobs)”| Method | Permission | Purpose |
|---|---|---|
bg.status | authenticated | Owner, limits, and queued and running counts. |
bg.browse | authenticated | Browse the caller’s folders to pick a job input; works without files. |
bg.jobs.submit | authenticated | Queue a job. Params key, folder, relative. Returns {job, duplicate}. |
bg.jobs.list | authenticated | List the caller’s jobs, newest first. |
bg.jobs.get | authenticated | One job by id. |
bg.jobs.cancel | authenticated | Cancel a job by id. |
bg.jobs.result | authenticated | A finished job’s result as JSON; not_ready before it finishes. |
bg.jobs.purge | administrators | Purge a user’s job data (owner: {user, uid}). |
bg.schedules.list | authenticated | List schedules. |
bg.schedules.create | authenticated | Repeat a job. Params key, jobId, intervalSeconds (3600, 86400 or 604800), consent: true. |
bg.schedules.disable | authenticated | Stop a schedule by id. |
bg.schedules.delete | authenticated | Delete a schedule by id. |
bg.schedules.enable | administrators | Start a schedule again. Params id, consent: true. |
A job key matches ^[A-Za-z0-9._-]{1,64}$. States are queued, running, succeeded, failed, canceled and interrupted; a failed job has an errorCode (Background jobs).
Login (login)
Section titled “Login (login)”| Method | Params | Purpose |
|---|---|---|
identity.status | none | Returns {enabled: true}. |
identity.session | bootstrap (optional) | Returns {user, uid, expiresAt} for the app session. With bootstrap: true and no app session, it starts one from the DSM sign-in. |
identity.login | account, password, otp (optional) | Signs the user in with their DSM account and starts an app session. |
identity.logout | none | Ends the app session. Returns {loggedOut: true}. |
All identity.* methods are public and need HTTPS and a same-origin JSON POST (Login).
Application Portal (portal)
Section titled “Application Portal (portal)”| Method | Permission | Purpose |
|---|---|---|
portal.status | authenticated | Reads the saved portal alias and whether it is active. |
Administrators set or clear the alias through ctx.portal (Application Portal).
Administrator operations (rootOps, delegate)
Section titled “Administrator operations (rootOps, delegate)”| Method | Permission | Params | Purpose |
|---|---|---|---|
executor.status | authenticated | none | Approved helper state: digests, version, ready, disabled, and tasks, the executor’s readback of its approval tasks as {state, checked_at}: checking, then ready, stale (older than 15 minutes) or failed. Read at start, every 10 minutes after a pass and every minute after a failure. A paused executor answers {ready: false, state: "paused", reason: "executor_not_listening", next}. |
executor.control | administrators | action: start, stop or purge | Starts, stops or purges the helper. |
root.run | administrators | name | Runs root/<name>.sh as root and returns {output}. No arguments. |
Delegate projects get executor.*. A failed root.run, or executor.status other than a paused executor, reaches the UI as internal. Executor account checks use native name/UID lookups both ways, plus expiry and current administrator membership; AD users need a reachable domain controller, and unknown providers or lookup failures refuse (Administrator operations).
Delegate (delegate)
Section titled “Delegate (delegate)”The default lifetime: until-revoked uses these methods.
| Method | Permission | Params | Purpose |
|---|---|---|---|
delegate.status | authenticated | none | State (ready, disabled, needs-admin-approval, blocked, needs-scope-confirmation), lifetime, destinations and scope. |
delegate.destination | authenticated | key | State of one destination: active, missing, reselection-required, needs-scope-confirmation or disabled. |
delegate.select_destination | authenticated | key, path | Picks a destination folder: checks write permission, then saves the grant. |
delegate.move_from_staging | authenticated | delegation_id, job_id, staging, name, size, optional conflict | Moves a finished file from staging into the chosen folder. name may contain folders, such as Album/CD1/01.flac; conflict is fail (default), overwrite or rename. |
delegate.operations.get | authenticated | delegation_id, job_id | State of a move. |
delegate.operations.cancel | authenticated | delegation_id, job_id | Cancels a move. |
delegate.operations.list | authenticated | none (send {}) | Lists moves. |
delegate.example.export | authenticated | key, job_id | Example export used by the save-later panel. |
delegate.disable, delegate.enable | administrators | none | Turn the integration off or on. Both end all grants. |
delegate.audit | authenticated | none | Package events; administrators see all, others their own. At most 256. |
Without lifetime, use delegate.create (job_id, ops, path, ttl_seconds 1 to 3600), delegate.list, delegate.revoke, delegate.jobs.submit, delegate.jobs.list and delegate.jobs.cancel, all authenticated; they need a DSM session cookie and token, else session_required (Delegate).
Executor protocol
Section titled “Executor protocol”These ops are generated from the executor protocol v1 schemas; ? marks an optional parameter, and ops that need a DSM session refuse with AUTH_DENIED (Executor protocol codes).
| Op | DSM session | Parameters |
|---|---|---|
delegate.audit | Required | — |
delegate.create | Required | job_id?, ops, scope, path?, ttl_seconds?, destination?, lifetime? |
delegate.disable | Required | — |
delegate.enable | Required | — |
delegate.list | Required | — |
delegate.revoke | Optional | delegation_id, job_id? |
files.cancelOperation | Optional | delegation_id, job_id |
files.checkPermission | Optional | delegation_id, job_id, path |
files.copy | Optional | delegation_id, job_id, path, dest_dir, conflict? |
files.createFolder | Optional | delegation_id, job_id, path, name, parents? |
files.delete | Optional | delegation_id, job_id, path, recursive?, permanent? |
files.info | Optional | delegation_id, job_id, path |
files.list | Optional | delegation_id, job_id, path |
files.move | Optional | delegation_id, job_id, path, dest_dir, conflict? |
files.moveFromStaging | Optional | delegation_id, job_id, staging, name, size, conflict? |
files.operationStatus | Optional | delegation_id, job_id |
files.read | Optional | delegation_id, job_id, path, max_bytes? |
files.rename | Optional | delegation_id, job_id, path, name |
files.taskCancel | Optional | delegation_id, job_id, task_id |
files.taskStatus | Optional | delegation_id, job_id, task_id |
files.write | Optional | delegation_id, job_id, staging, dest_dir, name, conflict? |
portal.register | Required | — |
portal.unregister | Required | — |
root.jobs.get | Required | job_id |
root.jobs.list | Required | — |
root.jobs.stop | Required | job_id |
root.run | Required | name, params? |
root.start | Required | name, params? |
status | Optional | — |
webapi.call | Optional | response_type?, delegation_id, job_id?, api, method, version, params |
Add a route in Go
Section titled “Add a route in Go”Register the handler in backend/internal/app/routes.go, then set its permission in permissions.json.
// routes.go: add to the list in Routesapi.HandleRequest("reports.list", cfg.listReports),package app
import ( "context" "encoding/json" "net/http"
"github.com/synopackageland/syno-pkg-land-sdk/api" "github.com/synopackageland/syno-pkg-land-sdk/filestation")
func (cfg Config) listReports(ctx context.Context, caller api.Caller, r *http.Request, params json.RawMessage) (any, error) { var in struct { Folder string `json:"folder"` } if err := decodeParams(params, &in); err != nil { return nil, err } if in.Folder == "" { return nil, api.BadRequest("folder is required") } return cfg.SessionFiles.List(ctx, caller, r, in.Folder, filestation.ListOptions{Limit: 50})}Registration functions
Section titled “Registration functions”| Function | Handler signature | Use it for |
|---|---|---|
api.Handle(method, h) | func(ctx, caller api.Caller, params json.RawMessage) (any, error) | Most routes. |
api.HandleRequest(method, h) | Adds the *http.Request after ctx. | Routes that call File Station or the executor with the user’s session. |
api.HandleResponse(method, h) | Adds http.ResponseWriter and *http.Request. Returns error. | Routes that set cookies or write the response. |
api.HandleStream(method, h) | func(ctx, caller, w, r) error | Upload and download. The method comes from the query string and the body is not JSON. |
The return value becomes data; the route’s permission always comes from permissions.json.
Caller and errors
Section titled “Caller and errors”| Item | Use |
|---|---|
caller.User() | The DSM user name. |
caller.Admin() | true for DSM administrators. |
caller.Authenticated() | true when a user is signed in. |
api.RequireAdmin(caller) | Returns admin_required when the caller is not an administrator; use it to reserve part of a shared route. |
api.BadRequest(msg) | Returns bad_request with your message. |
&api.Error{Code: "…", Message: "…"} | Your own code; the UI sees it. |
Any other error | Logged on the NAS, returned to the UI as internal. |
Derive owners from caller.User(); never trust a user name in params.
Capabilities from handlers
Section titled “Capabilities from handlers”| You need | Use |
|---|---|
| Files with the user’s permissions | cfg.SessionFiles.List, Info, CreateFolder, Upload and Download, each with ctx, caller and the request r. Needs files. |
| One interface for a request or delegate job | filestation.RequestContext{Caller, Request, Service}.Files() with List, Info, CreateFolder, CheckPermission and Write. Needs delegate. |
| File operations of a delegate job | delegate.JobContext.Files() adds CreateFolderAll, Rename, Read, and the task operations Copy, Move, Delete, TaskStatus and CancelTask. Each needs its operation in the delegate operations. |
| Background jobs | Call the bg.* methods from the UI. The worker is fixed and computes a SHA-256. |
| Save a file later, without a user session | Call service.Destination(ctx, caller, req, "save") while the user is present, keep Destination.ID, then service.MoveFromStaging(ctx, MoveParams{DelegationID, JobID, Staging, Name, Size}). |
| A root operation | The administrator’s UI calls root.run with the script name in root/<name>.sh; no generated UI calls it, so call ctx.call('root.run', {name}) yourself. |
UI client
Section titled “UI client”ctx is the DSM window’s context. Other helpers come from sdk (@synopackageland/sdk, headless) and sdk/vue (@synopackageland/sdk/vue; import @synopackageland/sdk/vue/style.css once) at the backend/go.mod SDK version, or check reports SDK_VERSION_MISMATCH; @synopackageland/ui is visual only.
| Helper | Where | Purpose |
|---|---|---|
ctx.call(method, params) | ctx | Calls a backend method; resolves with data, rejects with {code, message}. |
ctx.locale | ctx | The DSM language, such as en or zh-TW. |
ctx.reopen(fn) | ctx | Runs fn on each show or relaunch; returns a remover. |
ctx.launchParams | ctx | The opening launch’s string values: desktop link launchParam or SYNO.SDS.AppLaunch param. Untrusted. |
ctx.onLaunch(fn) | ctx | Runs fn(params) on each later launch with values; returns a remover. |
ctx.host | ctx | Window and file manager actions: setTitle, openApp, openURL, openFileManager, revealFile, subscribe. |
ctx.user | ctx | {name, isAdmin}; hide controls with it, but the backend decides access. |
ctx.files | ctx | {endpoint, token} for file transfers; with files. |
ctx.portal | ctx | status(), apply(alias), disable(), openControlPanel(), mountPanel(el); with portal. |
ctx.executor | ctx | Administrator approval: status(), authorize(password, scope?), control(action); with rootOps or delegate. |
ctx.t(key, params) | ctx | Translated text from i18n/messages. |
followLaunchRoute(ctx, navigate) | sdk | Calls navigate(route) with the route value of this and later launches (Native app guide). |
launchRoute(params), dsmLaunchURL(origin, packageId, params) | sdk | Read a safe app route from launch values; build a DSM desktop link. |
createNasProvider(ctx) | sdk | File provider for the picker: shares, list, info, createFolder, upload, download. |
createSession(ctx) | sdk/vue | Login session state and calls: login, bootstrap, logout, call. |
createBackgroundSaveFacade(ctx) | sdk | Wraps delegate.* for save-later panels. |
FilesPage, FileBrowser, NasPicker | sdk/vue | Vue file and folder browsing. |
LoginPage | sdk/vue | Vue sign-in form; needs https:. |
BackgroundPanel | sdk/vue | Vue job panel built on bg.browse. |
ExecutorSettings | sdk/vue | Vue panel for administrator approval of background access. |
ExecutorApproval | sdk/vue | Holds the pages until the executor is approved. With preload, pages mount hidden and read status alongside; ready keeps that instance, others discard it. |
useExecutorPreload() | sdk/vue | true while preloading; it turns false before pages unmount, so open teleported dialogs or toasts from watchPostEffect. AuthorizationGate waits by itself. |
PortalSettings | sdk/vue | Vue panel for the portal alias. |
// A Vue component with ctx as a propconst list = await ctx.call<{ files: { name: string; isdir: boolean }[] }>('reports.list', { folder: '/volume1/reports',})Limits
Section titled “Limits”| Limit | Value |
|---|---|
| Request body | 1 MiB |
| Time for one request | 20 seconds |
| App login session | 15 minutes at most |
| Sign-in attempts | 5 per minute per account, 20 per minute per address |
Request batches
Section titled “Request batches”ctx.batch and createClient().batch send one to eight independent JSON methods in one HTTP request.
const results = await ctx.batch!([ {method: 'app.status'}, {method: 'greeting.get'},])Results keep input order as {success: true, data} or {success: false, error}; each method keeps its permission check, and one failure leaves the others available. Transport failure rejects the batch. Calls share one App process for bridge methods. Order is unspecified, stream and cookie routes are refused, and batches never retry, so keep dependent writes separate; createSession(ctx).batch handles sessions and denials like call.