E9.2 Sending Array/DataSet to Connector POST REST

dtujo2022

Member
An orchestration that my team is working on is needs to make an external POST request to an external application. The data is formatted similar to this in orchestration output:

{
"var1": "abc",
"var2": "xyz",
"var3": 123,
"array": [
{
"avar1": 123,
"avar2": "abc",
"avar3": "xyz"
},
{
"avar1": 123,
"avar2": "abc",
"avar3": "xyz"
},
{
"avar1": 123,
"avar2": "abc",
"avar3": "xyz"
}
]
}
Within the orchestration what is the best way to bring those variables into the Connector? It would need to go in the POST body I can bring in the strings and numbers easily but not the array. I have seen taking that array and using a custom script to turn it in a single json string. I tried creating a JRuby custom extension and cannot have the array as an input. Whats the best way to go about this?
 
Last edited:
When I have a complex json that I need to post to a REST api, I will normally build the json in a Custom Request using JRuby. In your example, I would create a hash that contains var1, var2, var3, and array. Let's call it mainObject. I would then generate the json and assign it to the returnMap.

returnMap["jsonBody"] = JSON.generate(mainObject)

Then click Load Outputs to create the output.

In the body of your connector, use text substitution to enter load the json into the body. i.e. ${jsonBody}

Then in the transformations of your connector step, map the jsonBody output from your Custom Request to your Connector.
 
When I have a complex json that I need to post to a REST api, I will normally build the json in a Custom Request using JRuby. In your example, I would create a hash that contains var1, var2, var3, and array. Let's call it mainObject. I would then generate the json and assign it to the returnMap.

returnMap["jsonBody"] = JSON.generate(mainObject)

Then click Load Outputs to create the output.

In the body of your connector, use text substitution to enter load the json into the body. i.e. ${jsonBody}

Then in the transformations of your connector step, map the jsonBody output from your Custom Request to your Connector.
How do you get the array into the Custom Request without having to iterate over it? In transformation all I see are the var1, var, var3, not the array or the the variables from the array
 
You would pass it in as one input, and then use the Json class to parse it. For example, if you created a data request to retrieve some data you would turn on Return Raw Output on in the transformations of the data request step, save the orchestration, and then pass in output from the data request. Keep in mind the raw output json will look very different so you will need to review it so you know how to get the information you need out of it.
 
You would pass it in as one input, and then use the Json class to parse it. For example, if you created a data request to retrieve some data you would turn on Return Raw Output on in the transformations of the data request step, save the orchestration, and then pass in output from the data request. Keep in mind the raw output json will look very different so you will need to review it so you know how to get the information you need out of it.
I was able to get this to work, now how would you go about the same thing with Logic Extensions? I turned return raw output on for the LEXT but I do not see it as an option in transformation?
1706111841209.png
1706111830299.png

1706111924191.png
 
Last edited:
For Logix Extensions, my coworker and I figured out a way to format the output of a Logic Extension so it can be sent in a POST request. First abstract away the Logic extension in its Orchestration. In the return of the orchestration you manipulate the output grabbing the string and saving it to a string variable that would be set in the orchestration. Then in another orchestration, call the ORCH with the LEXT in it and then within the connector you can ${arraystring} and in transformation the returned string (which is the array) will be can then be mapped to ${arraystring}. NOTE that doing $esc{arraystring} does not work.
 
Back
Top