Skip to content

Script Management Service

This service provides functionality related to the scripting environment including usefull features such as sandbox execution & triggering your own solution event.

Operations

Events


Operations

Please note that bold arguments are required, while italic arguments are optional.

sandbox

Execute a Lua script as a string and return the execution result. No West Connectivity service calls or log print is Max execution time is 10 seconds.

Arguments

parameters (object) - Object containing service call parameters.

Name Type Description
script string Script content which want to be executed
timeout integer CPU timeout in seconds
Maximum: 10
Minimum: 1
Default: 1
parameters object, string, array, number, boolean The parameters passed to the script execution accessible in the "parameters".
If the provided parameters is an object, the sub-keys are also directly accessible by they name.

Responses

Code Body Type Description
200 object Returned data from script execution
default object Standard http responses

Object Parameter of 200 response:

Name Type Description
value number, object, string, boolean, array, null Value returned by the script execution

Object Parameter of default response:

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local scriptObj = {}
scriptObj.script = "return a + b"
scriptObj.parameters = {
    a = 1,
    b = 2
  }
local result = Scripts.sandbox(scriptObj)
print(result)
-- [Expected response]
-- {
--   "value": 3
-- }

trigger

Trigger an event from the active solution. The execution mode can be either:

  • sync (default): This is a blocking call and the result of the execution is returned.
  • async: The event is executed asynchronously. No result is returned.

Tips: You can define custom event under this service.

Arguments

parameters (object) - Object containing service call parameters.

Name Type Description
service ^(?![0-9])[a-zA-Z0-9]{2,63}$ Indicates the service to trigger by specifying the service alias. By default target this very service, as it allows custom events which would not get trigger by other mean.
Default: "scripts"
event ^(?![0-9])[a-zA-Z0-9_]{2,63}$ Indicates the event to trigger. Refer to West Connectivity Service documentation regarding the available events for each service. You can also defined event un-related to any other service by defining custom event under this service.
mode "sync", "async" Indicate the execution mode, blocking or asynchronously.
Default: "sync"
data number, string, object, array, null Parameter object transmitted to the subscribers event handler function.

Responses

Code Body Type Description
200 number, string, object, array, null Execution result
202 nil Asynchronously events triggered. No body data is returned
403 object Core service cannot use broadcast
404 object Service not found
default object Standard http responses

Object Parameter of 403 response:

Name Type Description
type string Error type
error string Error message
status integer Response code

Object Parameter of 404 response:

Name Type Description
type string Error type
error string Error message
status integer Response code

Object Parameter of default response:

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

-- Trigger the "Custom_Event" event of Scripts service
local event = {service="scripts", mode="sync", event="custom_event"}
local result = Scripts.trigger(event)
print(result)
-- [Expected response]
-- {
--   "status_code":204,
--   "status":204
-- }

Events

CustomEvent

This is a custom event that can only be triggered using the 'trigger' operation of this service. The event is named 'custom_event' and includes a 'data' argument.

Arguments

data (object) - The event trigger parameters

Name Type Description
data number, object, string, boolean, array, null Custom argument

Example

-- The "Custom_Event" is found on the Scripts service page. Users can access the Scripts service page through the Connectivity Platform UI and implement custom logic using the Lua editor available on the Scripts service page like:
local dataArgument = data
print(type(dataArgument))  
-- [Expected response]
-- number   

-- When implementing your application, how do you trigger the "Custom_Event" of the Scripts service? You can refer to this Lua code:
local eventData = {service="scripts", mode="sync", event="custom_event", data=42} 
local response = Scripts.trigger(eventData) 
print(response)
-- [Expected response]
-- {"status_code":204,"status":204}

Service Health Check

Operations

/api/v1/health

Enable the hosting system to check if service is active and running

Arguments

No Content

Responses

Name Type Description
200 string OK

Errors

No content