iobroker.rest-api
v2.0.3
Published
RESTful interface for ioBroker with GUI.
Downloads
220
Maintainers
Readme
REST-API adapter
This adapter uses Sentry libraries to automatically report exceptions and code errors to the developers. For more details and for information how to disable the error reporting see Sentry-Plugin Documentation! Sentry reporting is used starting with js-controller 3.0.
This is a RESTFul interface to read the objects and states from ioBroker and to write/control the states over HTTP Get/Post requests.
The purpose of this adapter is similar to simple-api. But this adapter supports long-polling and URL hooks for subscribes.
It has a beneficial web interface to play with the requests:
Usage
Call in browser http://ipaddress:8093/
and use Swagger UI to request and modify the states and objects.
Some request examples:
http://ipaddress:8093/v1/state/system.adapter.rest-api.0.memHeapTotal
- read state as JSONhttp://ipaddress:8093/v1/state/system.adapter.rest-api.0.memHeapTotal/plain
- read state as string (only value)http://ipaddress:8093/v1/state/system.adapter.rest-api.0.memHeapTotal?value=5
- write state with GET (only for back compatibility with simple-api)http://ipaddress:8093/v1/sendto/javascript.0?message=toScript&data={"message":"MESSAGE","data":"FROM REST-API"}
- send a message to javascript.0 in scriptscriptName
Subscribe to the state's or object's changes
Your application could get notifications by every change of the state or object.
For that, your application must provide an HTTP(S) end-point to accept the updates.
Example in node.js see here demoNodeClient.js
Long polling
This adapter supports a subscribing on data changes via long polling.
Example for browser could be found here: demoNodeClient.js
Web extension
This adapter can run as a web extension. In this case, the path is available under http://iipaddress:8082/rest
Notice
POST
is always for creating a resource (does not matter if it was duplicated)PUT
is for checking if resource exists then update, else create new resourcePATCH
is always for updating a resource
Commands
Additionally, you can execute many socket commands via special interface:
http://ipaddress:8093/v1/command/<commandName>?arg1=Value2&arg2=Value2
E.g.
http://ipaddress:8093/v1/command/getState?id=system.adapter.admin.0.alive
- to read the state ofsystem.adapter.admin.0.alive
http://ipaddress:8093/v1/command/readFile?adapter=admin.admin&fileName=admin.png
- to read the fileadmin.admin/admin.png
as JSON resulthttp://ipaddress:8093/v1/command/readFile?adapter=admin.admin&fileName=admin.png?binary
- to read the fileadmin.admin/admin.png
as filehttp://ipaddress:8093/v1/command/extendObject?id=system.adapter.admin.0?obj={"common":{"enabled":true}}
- to restart admin
You can request all commands with POST method too. As body must be an object with parameters. E.g.:
curl --location --request POST 'http://ipaddress:8093/v1/command/sendTo' \
--header 'Content-Type: application/json' \
--data-raw '{
"adapterInstance": "history.0",
"command": "getHistory",
"message": {"id": "system.adapter.admin.0.memRss","options": {"aggregate": "onchange", "addId": true}}
}'
You cannot send POST request to commands via GUI.
States
getStates(pattern)
- get the list of states for pattern (e.g. for system.adapter.admin.0.*). GUI can have problems by visualization of answer.getForeignStates(pattern)
- same as getStatesgetState(id)
- get state value by IDsetState(id, state)
- set state value with JSON object (e.g.{"val": 1, "ack": true}
)getBinaryState(id)
- get binary state by IDsetBinaryState(id, base64)
- set binary state by ID
Objects
getObject(id)
- get object by IDgetObjects(list)
- get all states and rooms. GUI can have problems by visualization of answer.getObjectView(design, search, params)
- get specific objects, e.g. design=system, search=state, params={"startkey": "system.adapter.admin.", "endkey": "system.adapter.admin.\u9999"}
setObject(id, obj)
- set object with JSON object (e.g.{"common": {"type": "boolean"}, "native": {}, "type": "state"}
)delObject(id, options)
- delete object by ID
Files
readFile(adapter, fileName)
- read file, e.g. adapter=vis.0, fileName=main/vis-views.json. Additionally, you can set option in query binary=true to get answer as file and not as jsonreadFile64(adapter, fileName)
- read file as base64 string, e.g. adapter=vis.0, fileName=main/vis-views.json. Additionally, you can set option in query binary=true to get answer as file and not as jsonwriteFile64(adapter, fileName, data64, options)
- write file, e.g. adapter=vis.0, fileName=main/vis-test.json, data64=eyJhIjogMX0=unlink(adapter, name)
- delete file or folderdeleteFile(adapter, name)
- delete filedeleteFolder(adapter, name)
- delete folderrenameFile(adapter, oldName, newName)
- rename filerename(adapter, oldName, newName)
- rename file or foldermkdir(adapter, dirName)
- create folderreadDir(adapter, dirName, options)
- read content of folderchmodFile(adapter, fileName, options)
- change file mode. E.g. adapter=vis.0, fileName=main/*, options ={"mode": 0x644}
chownFile(adapter, fileName, options)
- change file owner. E.g. adapter=vis.0, fileName=main/*, options ={"owner": "newOwner", "ownerGroup": "newgroup"}
fileExists(adapter, fileName)
- check if file exists
Admins
getHostByIp(ip)
- read host information by IP. e.g. by localhostreadLogs(host)
- read file name and size of log files. You can read them with http://ipaddress:8093/delState(id)
- delete state and object. Same as delObjectgetRatings(update)
- read adapter ratings (as in admin)getCurrentInstance()
- read adapter namespace (always rest-api.0)decrypt(encryptedText)
- decrypt string with system secretencrypt(plainText)
- encrypt string with system secretgetAdapters(adapterName)
- get objects of type "adapter". You can define optionally adapterNameupdateLicenses(login, password)
- read licenses from ioBroker.net portalgetCompactInstances()
- read list of instances with short informationgetCompactAdapters()
- read list of installed adapters with short informationgetCompactInstalled(host)
- read short information about installed adaptersgetCompactSystemConfig()
- read short system configgetCompactSystemRepositories()
getCompactRepository(host)
- read short repositorygetCompactHosts()
- get short information about hostsaddUser(user, pass)
- add new userdelUser(user)
- delete useraddGroup(group, desc, acl)
- create new groupdelGroup(group)
- delete groupchangePassword(user, pass)
- change user passwordgetAllObjects()
- read all objects as list. GUI can have problems by visualization of answer.extendObject(id, obj)
- modify object by ID with JSON. (.e.g.{"common":{"enabled": true}}
)getForeignObjects(pattern, type)
- same as getObjectsdelObjects(id, options)
- delete objects by pattern
Others
log(text, level[info])
- no answer - add log entry to ioBroker logcheckFeatureSupported(feature)
- check if feature is supported by js-controller.getHistory(id, options)
- read history. See for options: https://github.com/ioBroker/ioBroker.history/blob/master/docs/en/README.md#access-values-from-javascript-adapterhttpGet(url)
- read URL from server. You can set binary=true to get answer as filesendTo(adapterInstance, command, message)
- send command to instance. E.g. adapterInstance=history.0, command=getHistory, message={"id": "system.adapter.admin.0.memRss","options": {"aggregate": "onchange", "addId": true}}
listPermissions()
- read static information with function permissionsgetUserPermissions()
- read object with user permissionsgetVersion()
- read adapter name and versiongetAdapterName()
- read adapter name (always rest-api)clientSubscribe(targetInstance, messageType, data)
getAdapterInstances(adapterName)
- get objects of type "instance". You can define optionally adapterName
Changelog
2.0.3 (2024-07-13)
- (jkuenemund) Changed response for the endpoint get states to the dictionary in swagger
2.0.1 (2024-05-23)
- (foxriver76) ported to
@iobroker/webserver
- (theshengfui) Fixed history requests
- (bluefox) Minimum required node.js version is 16
1.1.0 (2023-05-03)
- (bluefox) Converting of the setState values to the according type
- (bluefox) Implemented file operations
1.0.5 (2023-03-27)
- (Apollon77) Prepare for future js-controller versions
1.0.4 (2022-08-31)
- (bluefox) Check if the port is occupied only on defined interface
1.0.2 (2022-07-27)
- (bluefox) Implemented binary read/write operations
1.0.1 (2022-07-27)
- (bluefox) Increased the max size of body to 100Mb
1.0.0 (2022-05-19)
- (bluefox) Final release
0.6.0 (2022-05-18)
- (bluefox) Added sendTo path
0.5.0 (2022-05-17)
- (bluefox) Some access errors were corrected
0.4.0 (2022-04-26)
- (bluefox) Added socket commands
0.3.6 (2022-04-22)
- (bluefox) Added object creation and enumerations reading
0.3.5 (2022-04-22)
- (bluefox) Allowed the reading of current subscriptions
0.3.4 (2022-04-20)
- (bluefox) Corrected subscription
0.3.1 (2022-04-15)
- (bluefox) First release
0.1.0 (2017-09-14)
- (bluefox) initial commit
License
Apache 2.0
Copyright (c) 2017-2024 bluefox [email protected]