Writing to Multiple Variables Simultaneously
- Updated2025-01-22
- 1 minute(s) read
Writing to Multiple Variables Simultaneously
Required permission: VariableWrite
Use the following format to update variable1 and variable2 of process1.
POST http://my_server:3580/nivariable/BatchWrite
POST JSON data
[{
"Url"
: "ni.var.psp://localhost/process1/variable1", "Value"
: "false"
}, {
"Url"
: "ni.var.psp://localhost/process1/variable2", "Value"
: "\"this is a new string value\""
}]
POST XML data
<?xml version="1.0" encoding="utf-8"?>
<BatchWriteArguments>
<BatchWriteArgument>
<Url>ni.var.psp://localhost/process1/variable1</Url>
<Value>false</Value>
</BatchWriteArgument>
<BatchWriteArgument>
<Url>ni.var.psp://localhost/process1/variable2</Url>
<Value>this is a new string value</Value>
</BatchWriteArgument>
</BatchWriteArguments>
If all variable writes succeed, the server returns the following response with a response body of an empty array:
HTTP/1.1 200 OK
Response body (JSON)
[]
Response body (XML)
<?xml version="1.0" encoding="utf-8"?>
<BatchWriteErrors>
</BatchWriteErrors>
If one or more variable writes fail, the response includes error descriptions. For example, if variable2 is not writable, the server returns the following:
HTTP/1.1 200 OK
Response body (JSON)
[{
"Url"
: "ni.var.psp://localhost/process1/variable2", "Error"
: {
"code"
: "", "message"
: {
"lang"
: "en-us", "value"
: "ni.var.psp://localhost/process1/variable2 is not writable"
}
}]
Response body (XML)
<?xml version="1.0" encoding="utf-8"?>
<BatchWriteErrors>
<BatchWriteError>
<Url><ni.var.psp://localhost/process1/variable2</Url>
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<code>0</code>
<message xml:lang="en-US">"ni.var.psp://localhost/process1/variable2 is not writable"</message>
</error>
</BatchWriteError>
</BatchWriteErrors>
Note Each batch writes to all selected writable variables and returns errors for all failed write attempts. A single failed write attempt does not stop the entire batch write.