Array Object - Returning Only first object

Having an issue with output Contract to return multiple of same Object in an array. I am only getting the first object to be returned instead of all objects returned in the array when comparing the outbound contract vs raw data.

Example:

[
{
"group": "01090",
"formID": 25566766,
"printBatchID": "",
"type": "5498",
"taxYear": 2022
},
{
"group": "03010",
"formID": 25566767,
"printBatchID": "",
"type": "5498",
"taxYear": 2022
},
{
"group": "03077",
"formID": 25566771,
"printBatchID": "",
"type": "PR 480.7C",
"taxYear": 2022
}
]

Return is

{
"group": "01090",
"formID": 25566766,
"printBatchID": "",
"type": "5498",
"taxYear": 2022,
"payer": {
"payerID": 164
}

Output Schema is only this and It is cutting out all data returned after first object

{
"title": "FormsArray",
"type": "array",
"properties": {},
"additionalItems": true
}

Your output contract likely needs to be an array -> object -> group/formId/type/etc.

Here are the screen shots of the output contract and the output, the returned Json has multiple objects with unique formID, type and taxYear

Under Apply Output Transformation, I can see all the other objects in the return but when it hits 11. Validate output against Schema, it restricts it to the first results.

I think that this may be a UI issue. I am assuming that you have flattening turned off.

If you open the developer console in your browser and run the test, you should see a call to the test route. After reproducing your scenario I see in the UI that it only shows one result, however in the actual response it has all three objects in the final result:


    "operations": [
        {
            "step": 1,
            "name": "Validate request body contains simple json (key-value pairs)",
            "success": true,
            "result": {
                "rawRequest": "{}",
                "integrationId": "0ae686b3-a23c-4709-8cdf-5ff7048713c4",
                "orgId": "640bc879-838e-476b-9766-90baa7c30894"
            }
        },
        {
            "step": 2,
            "name": "Validate draft definition",
            "success": true
        },
        {
            "step": 3,
            "name": "Validate request body against simple input schema",
            "success": true
        },
        {
            "step": 4,
            "name": "Resolve request translation map",
            "success": true,
            "result": {}
        },
        {
            "step": 5,
            "name": "Perform authentication",
            "success": true
        },
        {
            "step": 6,
            "name": "Resolve request URL template",
            "success": true,
            "result": "[GET] https://jasonmathison.mockable.io/customertest"
        },
        {
            "step": 7,
            "name": "Resolve request header templates",
            "success": true,
            "result": {}
        },
        {
            "step": 8,
            "name": "Resolve request body template",
            "success": true,
            "result": ""
        },
        {
            "step": 9,
            "name": "Execute",
            "success": true,
            "result": [
                {
                    "group": "01090",
                    "formID": 25566766,
                    "printBatchID": "",
                    "type": "5498",
                    "taxYear": 2022
                },
                {
                    "group": "03010",
                    "formID": 25566767,
                    "printBatchID": "",
                    "type": "5498",
                    "taxYear": 2022
                },
                {
                    "group": "03077",
                    "formID": 25566771,
                    "printBatchID": "",
                    "type": "PR 480.7C",
                    "taxYear": 2022
                }
            ]
        },
        {
            "step": 10,
            "name": "Resolve translation map",
            "success": true,
            "result": {
                "rawResult": "[ {\n  \"group\" : \"01090\",\n  \"formID\" : 25566766,\n  \"printBatchID\" : \"\",\n  \"type\" : \"5498\",\n  \"taxYear\" : 2022\n}, {\n  \"group\" : \"03010\",\n  \"formID\" : 25566767,\n  \"printBatchID\" : \"\",\n  \"type\" : \"5498\",\n  \"taxYear\" : 2022\n}, {\n  \"group\" : \"03077\",\n  \"formID\" : 25566771,\n  \"printBatchID\" : \"\",\n  \"type\" : \"PR 480.7C\",\n  \"taxYear\" : 2022\n} ]"
            }
        },
        {
            "step": 11,
            "name": "Apply output transformation",
            "success": true,
            "result": [
                {
                    "group": "01090",
                    "formID": 25566766,
                    "printBatchID": "",
                    "type": "5498",
                    "taxYear": 2022
                },
                {
                    "group": "03010",
                    "formID": 25566767,
                    "printBatchID": "",
                    "type": "5498",
                    "taxYear": 2022
                },
                {
                    "group": "03077",
                    "formID": 25566771,
                    "printBatchID": "",
                    "type": "PR 480.7C",
                    "taxYear": 2022
                }
            ]
        },
        {
            "step": 12,
            "name": "Validate output against schema",
            "success": true
        }
    ],
    "finalResult": [
        {
            "group": "01090",
            "formID": 25566766,
            "printBatchID": "",
            "type": "5498",
            "taxYear": 2022
        },
        {
            "group": "03010",
            "formID": 25566767,
            "printBatchID": "",
            "type": "5498",
            "taxYear": 2022
        },
        {
            "group": "03077",
            "formID": 25566771,
            "printBatchID": "",
            "type": "PR 480.7C",
            "taxYear": 2022
        }
    ],
    "success": true
}

Yes, flattening is turned off. So, in this instance, how would I be able to reference/loop through all the returned objects?

If you mean in architect, then you will have to take a different approach, as everything going to architect has to be flattened, and arrays have to have exactly 1 entry to be considered successful.

One option would be to take those results, and then return a key/value pair, with a JSON escaped version of the results.

Architect now has the tooling to unescape the json and iterate through it.

Another option would be to have the top level of your output contract be an object, that would then hold the array. That should be flattenable.

--Jason

What would be example be of doing the escaped version of the results?

the other option of utilizing the object at the top level would require us to modify the results of API call from either from the sender point or from the reception point of view, correct?

What would be example be of doing the escaped version of the results?
"successTemplate": "{ \"results\" : \"$esc.jsonString(${rawResult})\" }"

the other option of utilizing the object at the top level would require us to modify the results of API call from either from the sender point or from the reception point of view, correct?

You could change the successTemplate like this:
"successTemplate": "{ \"results\" : ${rawResult} }"
I'm not sure if that answers your question or not.

--Jason

so I elected to go the first option, now in the call flow i am doing jsonParse(return) to convert into a JSON format in the call flow to utilize.

For me to loop through the list of the of returned froms, would i want to store a varaible for count of formIDs, ,create a for loop for that instance and reference the array with jsonName.Array{currentloopinstance}.formID?

I have not worked with the Architect JSON tools much, but what you are describing seems reasonable.

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.