Skip to content

Script API

The Script API provides script creation, update, deletion, and execution operations.

MethodEndpointDescription
GET/api/scriptsScript list
GET/api/scripts/{id}Script details
POST/api/scriptsCreate a new script
PUT/api/scripts/{id}Update a script
DELETE/api/scripts/{id}Delete a script
GET/api/scripts/{id}/statusScript execution status

Accepts JavaScript code as a string and executes it on the server side. The script has full access to the ins.* API.

POST /api/scripts/runner
Content-Type: application/json
X-Space: <space_name>
{
"projectId": 153,
"name": "test-script",
"code": "var val = ins.getVariableValue('ActivePower_kW'); ins.toJSONStr(val);",
"log": false,
"compile": false
}
FieldTypeRequiredDescription
projectIdIntegerYesTarget project ID
nameStringYesScript identifier name
codeStringYesJavaScript code to execute
logBooleanNoEnable execution log
compileBooleanNoCompile before execution
bindingsObjectNoCustom variables to inject into the script

The result of the script’s last expression is returned directly:

HTTP/1.1 200 OK
Content-Type: application/json
359.91
Terminal window
# Login
curl -c cookies.txt -X POST http://localhost:8081/login \
-F "username=inscada" -F "password=1907"
# Read variable value
curl -b cookies.txt -X POST http://localhost:8081/api/scripts/runner \
-H "X-Space: claude" -H "Content-Type: application/json" \
-d '{
"projectId": 153,
"name": "read-value",
"code": "var val = ins.getVariableValue(\"ActivePower_kW\"); ins.toJSONStr(val);",
"log": false,
"compile": false
}'

Response:

{
"flags": { "scaled": true },
"date": 1774686685945,
"value": 359.91,
"extras": { "raw_value": 606.56 },
"variableShortInfo": {
"dsc": "Total active power",
"frame": "Energy-Frame",
"project": "Energy Monitoring Demo",
"device": "Energy-Device",
"name": "ActivePower_kW",
"connection": "LOCAL-Energy"
},
"dateInMs": 1774686685945
}
Terminal window
# Read multiple values
curl -b cookies.txt -X POST http://localhost:8081/api/scripts/runner \
-H "X-Space: claude" -H "Content-Type: application/json" \
-d '{
"projectId": 153,
"name": "read-multi",
"code": "var vals = ins.getVariableValues([\"ActivePower_kW\",\"Voltage_V\",\"Current_A\"]); ins.toJSONStr(vals);",
"log": false,
"compile": false
}'
Terminal window
# Write a value
curl -b cookies.txt -X POST http://localhost:8081/api/scripts/runner \
-H "X-Space: claude" -H "Content-Type: application/json" \
-d '{
"projectId": 153,
"name": "write-value",
"code": "ins.setVariableValue(\"Temperature_C\", {value: 55.0});",
"log": false,
"compile": false
}'
Terminal window
# Query statistics
curl -b cookies.txt -X POST http://localhost:8081/api/scripts/runner \
-H "X-Space: claude" -H "Content-Type: application/json" \
-d '{
"projectId": 153,
"name": "stats",
"code": "var end=ins.now(); var start=ins.getDate(end.getTime()-3600000); var stats=ins.getLoggedVariableValueStats([\"ActivePower_kW\"],start,end); ins.toJSONStr(stats);",
"log": false,
"compile": false
}'

Response:

{
"ActivePower_kW": {
"maxValue": 624.76,
"minValue": 305.11,
"avgValue": 470.95,
"sumValue": 74881.16,
"countValue": 159,
"medianValue": 482.58,
"firstValue": 464.04,
"lastValue": 543.08
}
}

This endpoint requires the RUN_SCRIPT permission. Scripts run on the server side using the Nashorn JavaScript engine and have full access to the ins.* API (Variable, Connection, Alarm, Script, Report, etc.).