RunScript
Executes a script on the server.
tip
Note that the data object will contain anything returned from the script.
tip
Pro-tip: If a script path is not specified in scriptName field, it will default to cloud code scripts root folder.
Service | Operation |
---|---|
script | RUN |
Method Parameters
Parameter | Description |
---|---|
scriptName | The name of the script with its absolute path to be run. |
scriptData | Data to be sent to the script in JSON format. |
Usage
http://localhost:3000
- C#
- C++
- Objective-C
- Java
- JavaScript
- Dart
- Cloud Code
- Raw
string scriptName = "path/to/script1";
string scriptData = "{\"arg1\":42,\"arg2\":true,\"arg3\":\"example\"}";
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("Success | {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("Failed | {0} {1} {2}", status, code, error));
};
_bc.ScriptService.RunScript(scriptName, scriptData, successCallback, failureCallback);
const char *scriptName = "path/to/script1";
const char *scriptData = "{\"arg1\":42,\"arg2\":true,\"arg3\":\"example\"}";
_bc->getScriptService()->runScript(scriptName, scriptData, this);
NSString *scriptName = @"path/to/script1";
NSString *scriptData = @"{\"arg1\":42,\"arg2\":true,\"arg3\":\"example\"}";
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[[_bc scriptService] runScript:scriptName
scriptData:scriptData
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
String scriptName = "path/to/script1";
String scriptData = "{\"arg1\":42,\"arg2\":true,\"arg3\":\"example\"}";
this; // implements IServerCallback
_bc.getScriptService().runScript(scriptName, scriptData, this);
public void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, JSONObject jsonData)
{
System.out.print(String.format("Success | %s", jsonData.toString()));
}
public void serverError(ServiceName serviceName, ServiceOperation serviceOperation, int statusCode, int reasonCode, String jsonError)
{
System.out.print(String.format("Failed | %d %d %s", statusCode, reasonCode, jsonError.toString()));
}
var scriptName = "path/to/script1";
var scriptData = {
"arg1": 42,
"arg2": true,
"arg3": "example"
};
_bc.script.runScript(scriptName, scriptData, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
var scriptName = "path/to/script1";
var scriptData = {
"arg1": 42,
"arg2": true,
"arg3": "example"
};
ServerResponse result = await _bc.scriptService.runScript(scriptName:scriptName, scriptData:scriptData);
if (result.statusCode == 200) {
print("Success");
} else {
print("Failed ${result.error['status_message'] ?? result.error}");
}
var scriptName = "path/to/script1";
var scriptData = {
"arg1": 42,
"arg2": true,
"arg3": "example"
};
var scriptProxy = bridge.getScriptServiceProxy();
var postResult = scriptProxy.runScript(scriptName, scriptData);
if (postResult.status == 200) {
// Success!
}
{
"service": "script",
"operation": "RUN",
"data": {
"scriptName": "path/to/script1",
"scriptData": {
"parm": "value"
}
}
}
JSON Response
{
"status": 200,
"data": {
"success": true
}
}
Common Error Code
Status Codes
Code | Name | Description |
---|---|---|
40363 | MISSING_SCRIPT | The script not found in specified folder. |