I'm using WSO2 Micro Integrator (WSO2 MI) and need to call multiple endpoints within an <iterate>
loop. The goal is to dynamically send requests to different API endpoints extracted from a JSON payload.
I have an <iterate>
mediator that loops through JSON data and extracts tokenEndpoint, client_id, and client_secret. I need to send a request to each endpoint within the loop.
<iterate expression="json-eval($)">
<target>
<sequence>
<log level="custom">
<property expression="json-eval($.tokenEndpoint)" name="tokenEndpoint"/>
</log>
<!-- Set Headers & Body for Token Request -->
<property name="Content-Type" scope="transport" type="STRING" value="application/x-www-form-urlencoded"/>
<property name="Accept" scope="transport" type="STRING" value="application/json"/>
<!-- Extract API Credentials -->
<property expression="json-eval($.tokenEndpoint)" name="TokenEndpoint" scope="default" type="STRING"/>
<property expression="json-eval($.client_id)" name="client_id" scope="default" type="STRING"/>
<property expression="json-eval($.client_secret)" name="client_secret" scope="default" type="STRING"/>
<payloadFactory media-type="json">
<format>{"client_id":"$1","client_secret":"$2"}</format>
<args>
<arg evaluator="json" expression="$.client_id"/>
<arg evaluator="json" expression="$.client_secret"/>
</args>
</payloadFactory>
<log level="full">
<property expression="json-eval($.body)" name="Token Request Payload"/>
</log>
<!-- Call API - Which Mediator to Use Here? -->
<call>
<endpoint>
<address uri="{TokenEndpoint}"/>
</endpoint>
</call>
</sequence>
</target>
</iterate>
Should I use the mediator or mediator?
Is there another recommended approach?
Should I use an explicit definition, or is there a better way to dynamically set the URL from JSON?
How do I ensure each API call executes independently inside the loop without waiting for the previous one to finish?
I'm using WSO2 Micro Integrator (WSO2 MI) and need to call multiple endpoints within an <iterate>
loop. The goal is to dynamically send requests to different API endpoints extracted from a JSON payload.
I have an <iterate>
mediator that loops through JSON data and extracts tokenEndpoint, client_id, and client_secret. I need to send a request to each endpoint within the loop.
<iterate expression="json-eval($)">
<target>
<sequence>
<log level="custom">
<property expression="json-eval($.tokenEndpoint)" name="tokenEndpoint"/>
</log>
<!-- Set Headers & Body for Token Request -->
<property name="Content-Type" scope="transport" type="STRING" value="application/x-www-form-urlencoded"/>
<property name="Accept" scope="transport" type="STRING" value="application/json"/>
<!-- Extract API Credentials -->
<property expression="json-eval($.tokenEndpoint)" name="TokenEndpoint" scope="default" type="STRING"/>
<property expression="json-eval($.client_id)" name="client_id" scope="default" type="STRING"/>
<property expression="json-eval($.client_secret)" name="client_secret" scope="default" type="STRING"/>
<payloadFactory media-type="json">
<format>{"client_id":"$1","client_secret":"$2"}</format>
<args>
<arg evaluator="json" expression="$.client_id"/>
<arg evaluator="json" expression="$.client_secret"/>
</args>
</payloadFactory>
<log level="full">
<property expression="json-eval($.body)" name="Token Request Payload"/>
</log>
<!-- Call API - Which Mediator to Use Here? -->
<call>
<endpoint>
<address uri="{TokenEndpoint}"/>
</endpoint>
</call>
</sequence>
</target>
</iterate>
Should I use the mediator or mediator?
Is there another recommended approach?
Should I use an explicit definition, or is there a better way to dynamically set the URL from JSON?
How do I ensure each API call executes independently inside the loop without waiting for the previous one to finish?
Share Improve this question edited yesterday Mark Rotteveel 109k226 gold badges155 silver badges219 bronze badges asked yesterday RoyRoy 212 bronze badges1 Answer
Reset to default 1You can use the Call mediator. Also, you need the Aggregate mediator to aggregate the responses from the endpoints.
You can follow this blog to get an idea about a similar Integration.
https://medium.com/think-integration/how-to-train-your-micro-integrator-b8c28cadca00
Note: If you are using Call mediator, then the aggregation should happen inside the InSequence itself.