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:
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
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
This adapter supports a subscribing on data changes via long polling.
Example for browser could be found here: demoNodeClient.js
This adapter can run as a web extension. In this case, the path is available under http://iipaddress:8082/rest
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
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.
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
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
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
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
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
- (jkuenemund) Changed response for the endpoint get states to the dictionary in swagger
- (foxriver76) ported to
@iobroker/webserver
- (theshengfui) Fixed history requests
- (bluefox) Minimum required node.js version is 16
- (bluefox) Converting of the setState values to the according type
- (bluefox) Implemented file operations
- (Apollon77) Prepare for future js-controller versions
- (bluefox) Check if the port is occupied only on defined interface
- (bluefox) Implemented binary read/write operations
- (bluefox) Increased the max size of body to 100Mb
- (bluefox) Final release
- (bluefox) Added sendTo path
- (bluefox) Some access errors were corrected
- (bluefox) Added socket commands
- (bluefox) Added object creation and enumerations reading
- (bluefox) Allowed the reading of current subscriptions
- (bluefox) Corrected subscription
- (bluefox) First release
- (bluefox) initial commit
Apache 2.0
Copyright (c) 2017-2024 bluefox [email protected]