Skip to content
Syno Package Land
Language: English

App API reference

A native app has one Go backend; its UI calls named methods such as greeting.get.

ctx.call(method, params) sends a same-origin JSON POST with the user’s DSM session.

PartValue
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 statusAlways 200, so DSM does not replace the body.
OriginSame 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.

Each method has one level, set outside the handler in backend/internal/api/permissions.json.

LevelWho can call
administratorsMembers of the DSM administrators group. This is the default.
authenticatedAny signed-in DSM user who passes the entry check.
publicAnyone. 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"
}
}
RuleValue
File shapeExactly schema, default and methods; default is administrators.
Method namesLowercase area.action, such as reports.list. Pattern ^[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*)+$, at most 128 characters.
SizeAt most 1024 methods and 64 KiB; duplicate keys are refused.
Registered methodsEvery listed method needs a handler.
Capability methodsFixed for nas.*, bg.*, identity.*, portal.*, executor.*, root.run and delegate.*.

check and build validate the file; errors use STANDALONE_API_PERMISSIONS_INVALID.

The entry field of dsm-package.yaml limits who can open the app; administrators always pass and public methods skip it (Manifest reference).

entryEffect
OmittedNo extra check. Any user who can open the window can call authenticated methods.
admin-onlyOnly administrators; others get admin_required.
app-privilegeOnly users DSM Application Privileges allow; others get app_privilege_denied. Needs at least one method that is not administrators; files or jobs suffice.

Add a capability with synopkgland add <name> or init --with <name>.

MethodPermissionPurpose
app.statusadministratorsPackage name, version, caller (user, admin), process, platform and time.
greeting.getadministratorsReads the example greeting. Returns {text}.
greeting.setadministratorsWrites 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.

MethodPermissionParamsPurpose
nas.session.statusauthenticatednoneReturns {mode: "filestation-session"} when file access is on.
nas.files.sharesauthenticatedoffsetLists Shared Folders the user can see.
nas.files.listauthenticatedpath, offset, limit (at most 100), sortBy (name, size, type, mtime), sortDirection (ASC, DESC)Lists a folder.
nas.files.infoauthenticatedpathReturns one file or folder.
nas.files.create_folderauthenticatedparent, nameCreates a folder. Returns {created: true}.
nas.files.uploadauthenticatedQuery 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.downloadauthenticatedQuery pathDownloads 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.

MethodPermissionPurpose
bg.statusauthenticatedOwner, limits, and queued and running counts.
bg.browseauthenticatedBrowse the caller’s folders to pick a job input; works without files.
bg.jobs.submitauthenticatedQueue a job. Params key, folder, relative. Returns {job, duplicate}.
bg.jobs.listauthenticatedList the caller’s jobs, newest first.
bg.jobs.getauthenticatedOne job by id.
bg.jobs.cancelauthenticatedCancel a job by id.
bg.jobs.resultauthenticatedA finished job’s result as JSON; not_ready before it finishes.
bg.jobs.purgeadministratorsPurge a user’s job data (owner: {user, uid}).
bg.schedules.listauthenticatedList schedules.
bg.schedules.createauthenticatedRepeat a job. Params key, jobId, intervalSeconds (3600, 86400 or 604800), consent: true.
bg.schedules.disableauthenticatedStop a schedule by id.
bg.schedules.deleteauthenticatedDelete a schedule by id.
bg.schedules.enableadministratorsStart 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).

MethodParamsPurpose
identity.statusnoneReturns {enabled: true}.
identity.sessionbootstrap (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.loginaccount, password, otp (optional)Signs the user in with their DSM account and starts an app session.
identity.logoutnoneEnds the app session. Returns {loggedOut: true}.

All identity.* methods are public and need HTTPS and a same-origin JSON POST (Login).

MethodPermissionPurpose
portal.statusauthenticatedReads 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)”
MethodPermissionParamsPurpose
executor.statusauthenticatednoneApproved 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.controladministratorsaction: start, stop or purgeStarts, stops or purges the helper.
root.runadministratorsnameRuns 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).

The default lifetime: until-revoked uses these methods.

MethodPermissionParamsPurpose
delegate.statusauthenticatednoneState (ready, disabled, needs-admin-approval, blocked, needs-scope-confirmation), lifetime, destinations and scope.
delegate.destinationauthenticatedkeyState of one destination: active, missing, reselection-required, needs-scope-confirmation or disabled.
delegate.select_destinationauthenticatedkey, pathPicks a destination folder: checks write permission, then saves the grant.
delegate.move_from_stagingauthenticateddelegation_id, job_id, staging, name, size, optional conflictMoves 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.getauthenticateddelegation_id, job_idState of a move.
delegate.operations.cancelauthenticateddelegation_id, job_idCancels a move.
delegate.operations.listauthenticatednone (send {})Lists moves.
delegate.example.exportauthenticatedkey, job_idExample export used by the save-later panel.
delegate.disable, delegate.enableadministratorsnoneTurn the integration off or on. Both end all grants.
delegate.auditauthenticatednonePackage 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).

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).

OpDSM sessionParameters
delegate.auditRequired—
delegate.createRequiredjob_id?, ops, scope, path?, ttl_seconds?, destination?, lifetime?
delegate.disableRequired—
delegate.enableRequired—
delegate.listRequired—
delegate.revokeOptionaldelegation_id, job_id?
files.cancelOperationOptionaldelegation_id, job_id
files.checkPermissionOptionaldelegation_id, job_id, path
files.copyOptionaldelegation_id, job_id, path, dest_dir, conflict?
files.createFolderOptionaldelegation_id, job_id, path, name, parents?
files.deleteOptionaldelegation_id, job_id, path, recursive?, permanent?
files.infoOptionaldelegation_id, job_id, path
files.listOptionaldelegation_id, job_id, path
files.moveOptionaldelegation_id, job_id, path, dest_dir, conflict?
files.moveFromStagingOptionaldelegation_id, job_id, staging, name, size, conflict?
files.operationStatusOptionaldelegation_id, job_id
files.readOptionaldelegation_id, job_id, path, max_bytes?
files.renameOptionaldelegation_id, job_id, path, name
files.taskCancelOptionaldelegation_id, job_id, task_id
files.taskStatusOptionaldelegation_id, job_id, task_id
files.writeOptionaldelegation_id, job_id, staging, dest_dir, name, conflict?
portal.registerRequired—
portal.unregisterRequired—
root.jobs.getRequiredjob_id
root.jobs.listRequired—
root.jobs.stopRequiredjob_id
root.runRequiredname, params?
root.startRequiredname, params?
statusOptional—
webapi.callOptionalresponse_type?, delegation_id, job_id?, api, method, version, params

Register the handler in backend/internal/app/routes.go, then set its permission in permissions.json.

// routes.go: add to the list in Routes
api.HandleRequest("reports.list", cfg.listReports),
reports.go
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})
}
FunctionHandler signatureUse 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) errorUpload 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.

ItemUse
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 errorLogged on the NAS, returned to the UI as internal.

Derive owners from caller.User(); never trust a user name in params.

You needUse
Files with the user’s permissionscfg.SessionFiles.List, Info, CreateFolder, Upload and Download, each with ctx, caller and the request r. Needs files.
One interface for a request or delegate jobfilestation.RequestContext{Caller, Request, Service}.Files() with List, Info, CreateFolder, CheckPermission and Write. Needs delegate.
File operations of a delegate jobdelegate.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 jobsCall the bg.* methods from the UI. The worker is fixed and computes a SHA-256.
Save a file later, without a user sessionCall 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 operationThe 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.

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.

HelperWherePurpose
ctx.call(method, params)ctxCalls a backend method; resolves with data, rejects with {code, message}.
ctx.localectxThe DSM language, such as en or zh-TW.
ctx.reopen(fn)ctxRuns fn on each show or relaunch; returns a remover.
ctx.launchParamsctxThe opening launch’s string values: desktop link launchParam or SYNO.SDS.AppLaunch param. Untrusted.
ctx.onLaunch(fn)ctxRuns fn(params) on each later launch with values; returns a remover.
ctx.hostctxWindow and file manager actions: setTitle, openApp, openURL, openFileManager, revealFile, subscribe.
ctx.userctx{name, isAdmin}; hide controls with it, but the backend decides access.
ctx.filesctx{endpoint, token} for file transfers; with files.
ctx.portalctxstatus(), apply(alias), disable(), openControlPanel(), mountPanel(el); with portal.
ctx.executorctxAdministrator approval: status(), authorize(password, scope?), control(action); with rootOps or delegate.
ctx.t(key, params)ctxTranslated text from i18n/messages.
followLaunchRoute(ctx, navigate)sdkCalls navigate(route) with the route value of this and later launches (Native app guide).
launchRoute(params), dsmLaunchURL(origin, packageId, params)sdkRead a safe app route from launch values; build a DSM desktop link.
createNasProvider(ctx)sdkFile provider for the picker: shares, list, info, createFolder, upload, download.
createSession(ctx)sdk/vueLogin session state and calls: login, bootstrap, logout, call.
createBackgroundSaveFacade(ctx)sdkWraps delegate.* for save-later panels.
FilesPage, FileBrowser, NasPickersdk/vueVue file and folder browsing.
LoginPagesdk/vueVue sign-in form; needs https:.
BackgroundPanelsdk/vueVue job panel built on bg.browse.
ExecutorSettingssdk/vueVue panel for administrator approval of background access.
ExecutorApprovalsdk/vueHolds 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/vuetrue while preloading; it turns false before pages unmount, so open teleported dialogs or toasts from watchPostEffect. AuthorizationGate waits by itself.
PortalSettingssdk/vueVue panel for the portal alias.
// A Vue component with ctx as a prop
const list = await ctx.call<{ files: { name: string; isdir: boolean }[] }>('reports.list', {
folder: '/volume1/reports',
})
LimitValue
Request body1 MiB
Time for one request20 seconds
App login session15 minutes at most
Sign-in attempts5 per minute per account, 20 per minute per address

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.