Define reusable blocks and call them from operations or other functions.
Functions keep larger scripts readable by moving repeated logic into named blocks. Definitions live in the top-level Functions array, and calls happen inside Do blocks with the Function command. Arguments can include %VariableName% substitutions or %{ expression }% expressions; see Variables.
Use the top-level Functions array to define reusable blocks that can be called from operations or from other functions.
{
"Functions": [
{
"Name": "HandleResponse",
"Parameters": [
{ "StatusCode": { "Type": "String", "Required": true } },
{ "Content": { "Type": "String", "Required": true } },
{ "AccountUserName": { "Type": "String", "Required": true } }
],
"Do": [
{ "Switch": {
"MatchValue": "%{StatusCode}%",
"Cases": [
{
"CaseValue": "(OK)|(NoContent)",
"Do": [
{ "Return": { "Value": true } }
]
}
]
}
}
]
}
]
}| Name | Type | Required? | Description |
|---|---|---|---|
Name |
String | Yes | Function name. Current validation follows the same naming rules as variables. |
Parameters |
Array of parameter definitions | No | Ordered input parameters exposed inside the function body. |
Do |
Array of commands | Yes | Commands that run when the function is called. |
| Name | Type | Required? | Description |
|---|---|---|---|
| Parameter name (object key) | String | Yes | Name exposed inside the function body, for example StatusCode or AccountUserName. |
Type |
Data type | Yes | Parameter type such as String, Secret, or Integer. |
Required |
Boolean | No | Whether the caller must supply a value. Defaults to true. |
DefaultValue |
Any | No | Default value used when the caller omits an optional parameter. |
Description |
String | No | Optional documentation text for the parameter definition. |
From samples/http/wordpress/WordPressHttp.json:
{
"Name": "HandleResponse",
"Parameters": [
{ "StatusCode": { "Type": "String", "Required": true } },
{ "Content": { "Type": "String", "Required": true } },
{ "AccountUserName": { "Type": "String", "Required": true } }
],
"Do": [
{ "Switch": {
"MatchValue": "%{StatusCode}%",
"Cases": [
{
"CaseValue": "(OK)|(NoContent)",
"Do": [
{ "Return": { "Value": true } }
]
},
{
"CaseValue": "Forbidden",
"Do": [
{ "Status": { "Type": "Changing", "Percent": 80, "Message": { "Name": "InsufficientPrivilegesAccessPassword" } } },
{ "Return": { "Value": false } }
]
}
]
}
}
]
}Use the Function command inside a Do block to invoke a named function. In current scripts, arguments are passed as an ordered Parameters array, and a returned value can be stored in ResultVariable.
{
"Function": {
"Name": "ConnectTelnet",
"Parameters": [ "%FuncUserName%", "%FuncPassword%" ],
"ResultVariable": "ConnectResult"
}
}| Name | Type | Required? | Description |
|---|---|---|---|
Name |
String | Yes | Name of the function to call. |
Parameters |
Array of values or expressions | No | Ordered argument values passed to the function definition. |
ResultVariable |
String | No | Variable name that receives the function's return value. |
IsSecret |
Boolean | No | Masks the stored return value when ResultVariable is used. Default is false. |
From samples/telnet/cisco-ios/GenericCiscoIosTelnet.json:
{
"Function": {
"Name": "ConnectTelnet",
"Parameters": [ "%FuncUserName%", "%FuncPassword%" ],
"ResultVariable": "ConnectResult"
}
}From samples/ssh/generic-linux-ssh-keys/GenericLinuxWithSSHKeySupport.json:
{
"Function": {
"Name": "LoginSsh",
"ResultVariable": "LoginResult",
"Parameters": [ "%FuncUserName%", "%FuncPassword%", "%UserKey::$%" ]
}
}Return values come from
Return, not from the last expression in the body.
Function calls store the return payload only when
ResultVariableis set. Without it, the function still runs, but the returned value is discarded unless a surroundingReturnor error path uses it directly.
There is no separate
Callkeyword in current scripts; invocation uses theFunctioncommand.