Pre and Post Processing Expressions and Multiple Outbound Requests
This procedure shows how to implement a flow with pre or post processing expressions, and multiple outbound requests.
The sample code shows how to:
- Pre-processes a task and build tenant information.
- Makes multiple outbound requests.
- Pre-processes the output to make a final request.
- Merges the output of two requests as a post-processing operation.
Complete sample code:
"flows": {
"compartmentIdFlow" : {
"id": "compartmentIdFlow",
"description": "compartmentIdFlow",
"specVersion": "0.8",
"version": "0.1",
"start": "startState",
"functions": [
{
"name": "generalRestFunc",
"type": "custom",
"operation": "connectivity::rest"
},
{
"name": "getTenantId",
"type": "expression",
"operation": "if .configuration.tenantId then .configuration.tenantId else .connectionProperties.TenancyOCID end"
},
{
"name": "mergeTenantsList",
"type": "expression",
"operation": "[.rootCompartment] + .childCompartments"
}
],
"states":[
{
"name":"startState",
"type":"operation",
"actions":[
{
"functionRef": "getTenantId",
"actionDataFilter": {
"toStateData": "${ .configuration.tenantId }"
}
},
{
"functionRef": {
"refName": "generalRestFunc",
"arguments": {
"uri": "${ \"https://identity.\" + .connectionProperties.region + \".oraclecloud.com/20160918/compartments/\" + .configuration.tenantId }",
"method": "GET"
}
},
"actionDataFilter": {
"results": "${ {keyName:.body.id, displayName:.body.name} }",
"toStateData": "${ .rootCompartment }"
}
},
{
"functionRef": {
"refName": "generalRestFunc",
"arguments": {
"uri": "${ \"https://identity.\" + .connectionProperties.region + \".oraclecloud.com/20160918/compartments\" }",
"method": "GET",
"parameters": {
"compartmentId": "${ .configuration.tenantId }",
"lifecycleState": "ACTIVE",
"compartmentIdInSubtree": true
}
}
},
"actionDataFilter": {
"results": "${ .body | map({keyName:.id, displayName:.name}) }",
"toStateData": "${ .childCompartments }"
}
},
{
"functionRef": "mergeTenantsList",
"actionDataFilter": {
"toStateData": "${ .output }"
}
}
],
"end": true
}
]
}
}