I have created an iterate mediator to retrieve some data from an API. There are some placeholder_ids stored inside myArray, and I want to fetch all the data from the API based on each placeholder_ids. Once all the data is retrieved, the iterate mediator should terminate. However, I am finding it difficult to implement this termination. Since I am new to WSO2 EI, can anyone help me with this?
Below you can see my current code. In the "log.info(response)". I could be able to print all the responses according to all ids.
<iterate expression="json-eval($.myArray)" sequential="true" preservePayload="true">
<target>
<sequence>
<property name="placeholder_id" expression="json-eval($.placeholder_id)" scope="default" type="STRING"/>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
<property name="ContentType" scope="axis2" type="STRING" value="application/json"/>
<sequence key="authentication-SEQ"/>
<property name="REST_URL_ABC" scope="axis2" type="STRING" value=""/>
<property name="HTTP_METHOD" scope="axis2" type="STRING" value="GET"/>
<property name="REST_URL_ABC" expression="fn:concat('/my_data/', get-property('placeholder_id'))" scope="axis2" type="STRING"/>
<call blocking="true">
<endpoint key="conf:endpoints/my-base-EP.xml"/>
</call>
<script description="Message transformation" language="js"><![CDATA[
//Here some scripts
var log = mc.getServiceLog();
var response = mc.getProperty('RESPONSE_BODY');
log.info("Print RESPONSE_BODY ....0");
log.info(response);
]]></script>
</sequence>
</target>
</iterate>
I also attempted to replace 'iterate' with 'foreach,' but it's also resulting in an error.
Iterate mediator should be coupled with an aggregate mediator. Hence try adding an aggregate mediator to the flow.
<aggregate id="YOUR_ITERATOR_ID">
<completeCondition>
<messageCount max="-1" min="-1"/>
</completeCondition>
<onComplete aggregateElementType="root" expression="json-eval($)">
<property expression="$body/*" name="response" scope="operation" type="OM"/>
<log level="full"/>
</onComplete>
</aggregate>