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.
 
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.
Kevin, I am struggling to pass the data request output to custom request. Could you please help could be as simple.
 
Kevin, I am struggling to pass the data request output to custom request. Could you please help could be as simple.
In your orchestration, click on the Transformation button of your data request, and then turn on Return Raw Output. Save the orchestration. In the Transformation section of your map <data request name>.output as an input into your custom request. That will pass in the json from the data request.
 
Kevin - I think what you build is similar to what we need on our side. I am using groovy for scripting.

Now struggling with how to create the body for the format I need. Here is the latest groovy that works but everything is inside for loop. I need to create more sections or objects.
import com.oracle.e1.common.OrchestrationAttributes;
import java.text.SimpleDateFormat;
import groovy.json.*;
HashMap<String, Object> main(OrchestrationAttributes orchAttr, HashMap inputMap)
{
HashMap<String, Object> returnMap = new HashMap<String, Object>();
//Input is the full output of the data request
String dataSetIn = (String)inputMap.get("CHRQuoteDataSet");

//create an object out of it
def jsonSlurper = new JsonSlurper();
def object = jsonSlurper.parseText(dataSetIn);

//get the record set
def dataset = object.fs_DATABROWSE_V55RR01J.data.gridData.rowset;

//def inputData = new JsonSlurper().parseText(inputMap.get("CHRQuoteDataSet"));
//def inputOrders = inputData.fs_DATABROWSE_V55RR01J.data.gridData.rowset;


def newDataSet = [];

for(def member : dataset) {


//create a new object for the resulting data set with the new date values
def newObj = [:]
newObj.documentNumber=member.F55RR01_DOCO;
newObj.customerCCode=member.F55RR01_55CCOD;
newObj.companyKey=member.F55RR01_KCOO;
newObj.country=member.F55RR01_CTR;
newObj.originCtr=member.F55RR01_OTCTR;
newObj.originZip=member.F55RR01_OTZIP;
newObj.shipDate=member.F55RR01_SHIPDT;
newObj.weightUnit = "Pounds";
newObj.freightClass=member.F55RR11_UWUM;
newObj.deliveryNo=member.F55RR01_DELN;
newObj.shipmentWeight=member.F55RR11_WGTS;
newObj.orderType=member.F55RR01_DCTO;
newObj.freightClass=member.F55RR11_55FRCL;
newObj.UKID=member.F55RR01_UKID;
newObj.postalcode=member.F55RR01_ADDZ;

//add to new output array
newDataSet.push(newObj);
}
//create a json string from the new data set
String newDataSetJson = JsonOutput.toJson(newDataSet);
//set that to the array variable defined in the custom
returnMap.put("GridData", newDataSetJson);

return returnMap;
}

Here is an example of JSON i need so I can pass into the api. Not sure how to get items:, origin: text before the brackets.
{
"items": [
{
"description": "AG 1100+ SWITCH FOR METAL PAN",
"freightClass": 70,
"actualWeight": 22,
"weightUnit": "Pounds",
"volumeUnit": "CubicFeet",
"declaredValue": 686.4,
"packagingCode": "CAS",
"productCode": "AG 1100+ SWITCH FOR METAL PAN",
"productName": "AG 1100+ SWITCH FOR METAL PAN",
"isStackable": false,
"nmfc": 70,
},
],
"origin": {
"locationName": ".",
"address1": "12128 New Berlin Rd",
"city": "Jacksonville",
"stateProvinceCode": "FL",
"countryCode": "US",
"postalCode": 32226
},
"destination": {
"locationName": "CARRIER SOUTHEAST 1850",
"address1": "1711 CORPORATION PKY",
"city": "RALEIGH",
"stateProvinceCode": "NC",
"countryCode": "US",
"postalCode": 27604
},
"shipDate": "2024-03-13",
"customerCode": "C8598560",
"transportModes": [
{
"mode": "LTL"
},
{
"mode": "Parcel"
}
]
}
 
It is really a matter of breaking down the json you provided.

Let's call the overall object "order". This will contain the rest of the information.

order = [:]

Then you need to create arrays items and transportModes
order.items = []
order.transportModes = []
You will create objects and add them to the appropriate array.

You will create objects for origin and destination
order.origin = [:]
order.destination = [:]

Of course you will need to add all of the information to the various objects you create to complete map.

Then you can use JsonOutput.toJson(order) to generate the required json from the map you created.
 
Kevin, being new to Groovy, not sure what the syntax would be to write these statements,
 
Back
Top