1 Reply Latest reply on Jul 22, 2021 7:01 AM by Jon Nettum

    How to return a list output in CAI when field type is Any?

    Jon Nettum New Member

      Hi,

       

      I need to create an API in CAI that returns a list response body in successful scenarios, and a single object response body in erroneous scenarios.

       

      Successful scenario example response body:

      [

           {

           "Field1": "Success",

           "Field2": "Test"

           },

           {

           "Field1": "Success1",

           "Field2": "Test1"

           }

      ]

       

      Erroneous scenario example response body:

      {

           "error": "Something went wrong",

           "detail": "123-123-123"

      }

       

      How can I achieve such responses? I have tried to have one output field of type Any, and return whole payload.

      That returns the error response correctly. For the success response, I try to return something like below, but it returns only the first element as an object, although it seem to work in Informatica.

      where o_sub_ResponseBody_Success is something like:

       

      <root xmlns:m="urn:informatica:ae:xquery:json2xml:meta-data">

        <elements m:isArray='true'>

          <Field1>Success</Field1>

          <Field2>Test</Field2>

        </element>

        <elements m:isArray='true'>

          <Field1>Success1</Field1>

          <Field2>Test1</Field2>

        </element>

      </root>

       

      Only below object is returned in my Postman

      {

           "Field1": "Success",

           "Field2": "Test"

      }

       

      , although this is the value in the CAI console:

      <sf:field name="o_Response" objectType="$po:$any">

        <elements xmlns:m="urn:informatica:ae:xquery:json2xml:meta-data" xmlns:type="http://schemas.informatica.com/spi/types/2013/12/spi-interface/" m:isArray="true">

         <Field1>Success</Field1>

         <Field2>Test</Field1>

      </elements>

      <elements xmlns:m="urn:informatica:ae:xquery:json2xml:meta-data" xmlns:type="http://schemas.informatica.com/spi/types/2013/12/spi-interface/" m:isArray="true">

         <Field1>Success1</Field1>

         <Field2>Test1</Field1>

      </elements>

      </sf:field>

       

      To simply return the response as o_sub_ResponseBody_Success is of course possible, but it's not according to my requirements. To change the erroneous response to a list is neither an option.

       

      If someone can help in this, it would be great!

       

       

      Br,

      Jon

        • 1. Re: How to return a list output in CAI when field type is Any?
          Jon Nettum New Member

          I created a support case. The responded solution is added below, it solved my problem.

           

          In a CAI Process, the output is generated based on output fields. As such, object list fields will be always treated as arrays, and single object fields will not accommodate more than one object.

          Hence, in this case, using Any or List of Any will not give you the desired output. However, we can set the output field as whole payload of the type attachment to achieve your use case. More details on the same available in the KB below:
          https://knowledge.informatica.com/s/article/632105?language=en_US

          I have also attached a sample process to show how the response will vary for success and error scenarios. Kindly import it into your org and use it as reference.

          NOTES:
          1. The current process is set to give the success output as response now. To change to error response, please change the field name in the last assignment step.
          2. '&#13;' is the HTML encoding for newline character, added for readability. This character can be removed from the expression without causing any validation errors.
          3. Please be advised that this is a sample process based on a particular input and output. Please use it only for reference and modify the logic as per your requirement.