This document describes the Export/Import endpoints, request/response schemas and examples. All responses use the standardized wrapper:
{
"success": true|false,
"data": { ... },
"error": { "code": "...", "message": "...", "details": ... },
"meta": { ... },
"timestamp": "RFC3339",
"request_id": "..."
}
- List plugins:
GET /api/v1/export/plugins - Plugin info:
GET /api/v1/export/plugins/{name} - Plugin schema:
GET /api/v1/export/plugins/{name}/schema - Generic export:
POST /api/v1/export - Preview export:
POST /api/v1/export/preview - Get result:
GET /api/v1/export/{id}(andGET /api/v1/export/backup/{id}). The server keeps a result in memory, and after a restart the answer comes from the history record instead, with the same fields but nochecksum,warningsormetadata, only the first error, and the time the record was saved ascreated_at. An id with no result and no record answers404. - Download:
GET /api/v1/export/{id}/download - History:
GET /api/v1/export/history(pagination:page,page_size; filters:plugin,success) - History item:
GET /api/v1/export/history/{export_id} - Statistics:
GET /api/v1/export/statistics - Backup export:
POST /api/v1/export/backup - Backup download:
GET /api/v1/export/backup/{id}/download - GitOps export:
POST /api/v1/export/gitops.config.output_pathis a directory below the export directory (see Safe Downloads; defaultgitops; the export directory itself is refused) and must be a new or empty directory, or one an earlier GitOps export wrote. Such a directory holds a.shelly-manager-gitopsmarker file, or theexport-summary.yamlfile that earlier versions wrote, as a regular file; an export replaces every file in it, so files you add there are removed by the next export. Any other non-empty directory answers400and is left untouched. Group and device type names become one directory name each: lower case, with/,\, spaces and a few other characters replaced.config.include_commonandconfig.include_templatesdefault totruewhen left out, in the export and in the preview; sendfalseto leave the common file or the templates out. A value that is not a boolean answers400. - GitOps download:
GET /api/v1/export/gitops/{id}/downloadstreams a zip of the export directory (application/zip, file name<directory name>.zip, files by their relative paths, built as it is sent). It zips only a directory that still holds the.shelly-manager-gitopsmarker file as a regular file, and answers403for any other; the marker is left out of the archive. A symlink inside the tree is skipped, never followed, and a path outside the export base directory answers403. Files someone added to the directory after the export are in the archive too. A failure before the first byte answers500. A failure after it (a file that vanishes or becomes unreadable, or the request deadline passing mid-transfer) cuts the connection without the end of the stream, so the client sees a failed transfer and never a complete-looking archive. - GitOps list, result and preview use the generic routes:
GET /api/v1/export/history?plugin=gitops,GET /api/v1/export/{id}andPOST /api/v1/export/previewwithplugin_name: "gitops". The history item'sfile_sizeis the total size of the exported files. - GitOps delete:
DELETE /api/v1/export/gitops/{id}removes the history record and answers204. It never removes the exported files. An id that is not a GitOps export answers404. - Export scheduling is not available. The former scheduling routes were removed because no scheduler executed the stored definitions.
POST /api/v1/export
{
"plugin_name": "backup|gitops|<plugin>",
"format": "sma|yaml|sqlite|...", // the backup plugin takes "sqlite" only
"config": { ... },
"filters": { ... },
"output": { "type": "file|webhook", "destination": "/path/to/file" },
"options": { "dry_run": false, "validate_only": false }
}
The generic export, its preview and the GitOps export replace every saved
secret with the marker [REDACTED]: the values under a secret-named key (a
name that contains pass, pwd, psk, secret or token, or ends in key)
in the device settings, the device configurations, the templates and the
template variables. This holds for the JSON, YAML, GitOps and SMA plugins. A
secret under a key that holds a list or an object is replaced throughout. An
empty value stays empty, except in the SMA export, whose own wider key rule
replaces a matching field whatever it holds. Set "exclude_sensitive": false
in config to ask for a full export with the secrets in clear.
Only the SMA import reads the marker, as "keep the stored value". The JSON, YAML and GitOps plugins have no import, so a file they wrote cannot be restored.
The backup plugin is not covered: it writes a database snapshot, which holds
every secret by design, so protect that file as you protect the database. The
manager has no route that writes a stored import/export record to a device: the
only device write is the apply, POST /api/v1/devices/{id}/config/new/apply,
which sends the desired configuration.
POST /api/v1/export/preview
{
... same body as export ...
}
200 OK
{
"success": true,
"data": {
"preview": {
"success": true,
"record_count": 123,
"estimated_size": 45678,
"warnings": []
},
"summary": {
"record_count": 123,
"estimated_size": 45678
}
},
"timestamp": "...",
"request_id": "..."
}
duration is a number of nanoseconds, in the import result as well.
{
"success": true,
"data": {
"export_id": "exp_...",
"plugin_name": "...",
"format": "...",
"output_path": "/abs/path/file.ext",
"record_count": 100,
"file_size": 4096,
"checksum": "sha256:...",
"duration": 123000000,
"warnings": []
},
"timestamp": "..."
}
page(int): 1-based page. Invalid or<=0defaults to1. Non-integer values default to1.page_size(int): page size. Values>100default to20.0or omitted returns a single page with all items for endpoints that support it.plugin(string): case-sensitive plugin name filter. Unknown names return an empty list.success(bool): acceptstrue/false,1/0,yes/no(case-insensitive). Invalid values are treated as no filter (or may be interpreted as false depending on endpoint implementation; see tests for current behavior).
- Generic import:
POST /api/v1/import - Preview import:
POST /api/v1/import/preview - Get result:
GET /api/v1/import/{id}. After a restart the answer comes from the history record, with the same fields but nochanges,warningsormetadata, only the first error, and the time the record was saved ascreated_at. An id with no result and no record answers404. - Check a stored backup:
POST /api/v1/import/restore-previewwith{"backup_id": "<export id>"}. It takes no path: the file is the one the export history records for that id, and it must be a regular file named like a backup inside the export directory. The answer says whether the file is present and can be opened, with its size and record count. It checks nothing of the file's contents and restores nothing. An empty file, or one the server cannot open, answers200withvalid: falseand a general message inerrors(never a path). An unknown id, or an id of another plugin, answers404; a failed export, or a file that is missing, outside the export directory or not a regular backup file, answers422; a body with any other field answers400. - Restore a stored SQLite backup:
POST /api/v1/import/restorewith{"backup_id": "<export id>", "dry_run": false}. Like the check above it takes no path, anddry_runis read from this body field only. The server unpacks a.sqlite.gzor.sqlite.zipbackup into a staging directory beside the database, checks the SQLite header, runsPRAGMA integrity_checkand looks for thedevicestable, then answers202"applies at the next start". It never replaces the live database while the server runs; the operator restarts the server (in Kubernetes, restart the pod). A dry run runs the same checks, stages nothing and answers200. A backup that fails a check, or that needs more free space than the database's directory has, answers422with the reason (never a path); a body with any other field answers400. Staging a second backup replaces the first.GET /api/v1/import/restoreanswers{pending, last_result}: the staged backup, and what the last start did with one (applied, orfailedwith the reason).DELETE /api/v1/import/restorecancels a staged restore (204, or404when none is staged). With PostgreSQL or MySQL all three answer501.POST /api/v1/importand/import/previewstill refuse every source for the backup plugin with501. - GitOps import:
POST /api/v1/import/gitops - GitOps preview:
POST /api/v1/import/gitops/preview - History:
GET /api/v1/import/history(pagination:page,page_size; filters:plugin,success) - History item:
GET /api/v1/import/history/{import_id} - Statistics:
GET /api/v1/import/statistics
POST /api/v1/import
{
"plugin_name": "gitops|<plugin>", // "backup" is refused with 501: see "Check a stored backup"
"format": "sma|yaml|...",
"source": { "type": "file|url|data", "path": "/path" },
"config": { ... },
"options": {
"dry_run": false,
"validate_only": false,
"force_overwrite": false,
"backup_before": false
}
}
The API enforces dry run + validate-only for preview routes.
POST /api/v1/import/preview
{
... same body as import ...
}
200 OK
{
"success": true,
"data": {
"preview": {
"success": true,
"import_id": "imp_...",
"records_imported": 0,
"records_skipped": 0,
"changes": [ { "type": "create|update|delete", "resource": "device|config|template", ... } ],
"warnings": []
},
"summary": {
"will_create": 2,
"will_update": 3,
"will_delete": 0
}
},
"timestamp": "..."
}
{
"success": true,
"data": {
"success": true,
"import_id": "imp_...",
"plugin_name": "...",
"format": "...",
"records_imported": 10,
"records_skipped": 1,
"duration": 250000000,
"changes": [ ... ],
"warnings": []
}
}
Same semantics as Export history: page, page_size, plugin (case-sensitive), and success value parsing.
Common error codes include VALIDATION_FAILED, INTERNAL_SERVER_ERROR, and NOT_FOUND. Details are provided in error.details when safe.
- Admin-only endpoints: All export/import operations, downloads, previews, results, schedules, history and statistics require admin authorization when an admin API key is configured.
- Provide either header
Authorization: Bearer <ADMIN_KEY>orX-API-Key: <ADMIN_KEY>. - If no admin key is configured, endpoints remain open (development mode). Configure
security.admin_api_keyto enable protection.
- Exports and downloads are confined to one export directory. It is
sync.export_base_dirif set, elseexport.output_directory, else./data/exports. The server creates it at start-up. - A relative
output_path(or output destination) is joined under the export directory; empty means the directory itself. An absolute path must already be inside it. A path that leaves it, by.., an absolute path elsewhere or a symbolic link, is refused with400and a message naming the export directory. - A download is served only for a file inside the export directory; otherwise the API returns
403 FORBIDDEN. An export recorded earlier outside it can no longer be downloaded. The one exception is a backup with no export directory configured: it is served from./data/backups, where the backup plugin writes it. - The check is made before the write. The SMA, GitOps, JSON, YAML and backup exports then write through the opened export directory, which refuses any link that leads out of it, and also a link whose target is an absolute path, even one that points inside.
The Backup plugin takes a database snapshot via the active DB provider.
- SQLite behavior:
config.compression = false→ output file*.sqliteconfig.compression = true→ output file*.sqlite.gz- No
.tar.gzcontainer; single-file outputs only. - The snapshot is one consistent copy of every committed write, including writes that are
still in the
-walfile (SQLiteVACUUM INTO). - While it runs, the backup needs free space for one full, uncompressed copy of the database in
a temporary
.backup-*directory beside the live database file (so on the database's disk, not in the backup directory), even when compression is on. The directory is removed afterwards. A crash can leave it behind; delete it by hand. The directory is the one of the file the DSN names: afile:prefix and a?query are not part of the path. - The database has one connection, so every other query waits until the snapshot is written. For a small database that is seconds.
- Backup directory: a backup is written only inside one directory. That is the export directory (
sync.export_base_dir, elseexport.output_directory) when one of them is set, and./data/backups(relative to the working directory) when neither is.config.output_pathis optional; empty means that directory. A relativeoutput_pathjoins under the export directory when one is set, and is relative to the working directory when it is not. Anoutput_paththat is not inside the backup directory answers400with the directory in the reason, and the requested path is not created. The check follows symbolic links before the write: a path whose deepest existing part leads out of the backup directory through a link is refused. The backup directory itself is created if it is missing, before the path is checked, so a refused request can still leave an empty backup directory. The backup file is written through the opened backup directory, which refuses a link swapped in between the check and the write. The result'soutput_pathis an absolute path. A backup is downloaded from that same directory. To keep backups elsewhere, setsync.export_base_dir; the restore routes checkexport.output_directory, so set both to the same directory.
Request example (SQLite):
POST /api/v1/export/backup
{
"name": "Pre-maintenance snapshot",
"description": "DB snapshot before changes",
"format": "sqlite",
"config": {
"output_path": "./data/backups",
"compression": true
}
}
Note: JSON/YAML/SMA live under “Content Exports” and use the generic export endpoints. The Backup endpoint is for provider-level snapshots only.