Hi All, We have resolved this issue by calling the template itself recursively with the use of filter mediator and aggregate the responses in the required format using the enrich mediator as follows:
<?xml version="1.0" encoding="UTF-8"?> <template name="getLeadActivities" xmlns="http://ws.apache.org/ns/synapse"> <!-- Required parameters --> <parameter name="activityTypeIds" description="Comma separated list of activity type ids."/> <parameter name="nextPageToken" description="Used to paginate through large result sets."/> <!-- Optional parameters --> <parameter name="listId" description="The Marketo list id."/> <parameter name="batchSize" description="The number of records to be returned in a single call."/> <sequence> <property name="uri.var.activityTypeIds" expression="$func:activityTypeIds"/> <property name="uri.var.listId" expression="$func:listId"/> <property name="uri.var.batchSize" expression="$func:batchSize"/> <property name="uri.var.nextPageToken" expression="$func:nextPageToken"/> <script language="js"> <![CDATA[ var activityTypeIds = mc.getProperty('uri.var.activityTypeIds'); var query=""; var ids=activityTypeIds.split(','); for(var i = 0; i < ids.length; i++){ query+='activityTypeIds='+ids[i]+'&'; } mc.setProperty('uri.var.activityTypeId', query); ]]> </script> <filter xpath="(not(get-property('uri.var.batchSize') = '' or (not(string(get-property('uri.var.batchSize'))))))"> <then> <property name="uri.var.apiParameters" expression="fn:concat(get-property('uri.var.apiParameters'),'batchSize=',get-property('uri.var.batchSize'),'&')"/> </then> </filter> <filter xpath="(not(get-property('uri.var.listId') = '' or (not(string(get-property('uri.var.listId'))))))"> <then> <property name="uri.var.apiParameters" expression="fn:concat(get-property('uri.var.apiParameters'),'listId=',get-property('uri.var.listId'))"/> </then> </filter> <call> <endpoint> <http method="get" uri-template="{uri.var.apiUrl}/activities.json?{uri.var.activityTypeId}&nextPageToken={uri.var.nextPageToken}&{uri.var.apiParameters}"/> </endpoint> </call> <property name="nextPageToken" expression="//nextPageToken/text()" scope="default" type="STRING"/> <property name="moreResult" expression="//moreResult/text()" scope="default" type="STRING"/> <enrich> <source type="property" property="RESULTS"/> <target type="body" action="child"/> </enrich> <enrich> <source type="custom" clone="true" xpath="//result"/> <target type="property" property="RESULTS"/> </enrich> <filter xpath="((get-property('moreResult') = 'true' ))"> <then> <header name="Authorization" expression="fn:concat('Bearer ',get-property('accessToken'))" scope="transport"/> <marketo.getLeadActivities> <listId>{get-property('uri.var.listId')}</listId> <activityTypeIds>{get-property('uri.var.activityTypeIds')}</activityTypeIds> <batchSize>{get-property('uri.var.batchSize')}</batchSize> <nextPageToken>{get-property('nextPageToken')}</nextPageToken> </marketo.getLeadActivities> </then> </filter> <payloadFactory media-type="json"> <format> { "activities":$1 } </format> <args> <arg expression="get-property('RESULTS')"/> </args> </payloadFactory> </sequence> </template> @Vanji and @Senduran, Thank you for your suggestions. On Wed, Apr 1, 2015 at 9:48 AM, Keerthika Mahendralingam <keerth...@wso2.com > wrote: > Thank you Chanaka and Malaka. > > On Tue, Mar 31, 2015 at 9:06 PM, Malaka Silva <mal...@wso2.com> wrote: > >> Hi Keerthika, >> >> Yes agree with Chanakaf. Similar is done with Salesforce query and >> querymore. You can follow similar approach. >> >> [1] >> https://docs.wso2.com/display/ESBCONNECTORS/Salesforce+Connector#SalesforceConnector-Queryingrecords >> [2] >> https://github.com/wso2-dev/esb-connectors/blob/master/salesforce/1.0.0/src/main/resources/salesforce/queryMore.xml >> >> >> >> On Tue, Mar 31, 2015 at 7:58 PM, Chanaka Fernando <chana...@wso2.com> >> wrote: >> >>> Hi Keerthika, >>> >>> This is a custom requirement which is more like a while loop. You need >>> to write a class mediator to implement this logic since ESB does not have a >>> construct similar to while loop. >>> >>> Thanks, >>> Chanaka >>> >>> On Tue, Mar 31, 2015 at 6:56 PM, Keerthika Mahendralingam < >>> keerth...@wso2.com> wrote: >>> >>>> Hi All, >>>> >>>> When we invoke a method in Marketo API we are getting the following >>>> response: >>>> >>>> { >>>> "requestId":"a9ae#148add1e53d", >>>> "success":true, >>>> >>>> >>>> "nextPageToken":"GIYDAOBNGEYS2MBWKQYDAORQGA5DAMBOGAYDAKZQGAYDALBRGA3TQ===", >>>> "moreResult":true, >>>> "result":[ >>>> { >>>> "id":2, >>>> "leadId":6, >>>> "activityDate":"2013-09-26T06:56:35+0000", >>>> "activityTypeId":12 >>>> }, >>>> { >>>> "id":3, >>>> "leadId":9, >>>> "activityDate":"2013-12-28T00:39:45+0000", >>>> "activityTypeId":1 >>>> } >>>> ] >>>> } >>>> >>>> If the moreResult attribute is true in the response, we need to call >>>> this method until the moreResult attribute returns false. The nextPageToken >>>> returned from the previous call need to be reused for the next iteration of >>>> this call. How can we do this? >>>> >>>> -- >>>> <dev-requ...@wso2.org> >>>> Keerthika Mahendralingam >>>> Associate Software Engineer >>>> Mobile :+94 (0) 776 121144 >>>> keerth...@wso2.com >>>> WSO2, Inc. >>>> lean . enterprise . middleware >>>> >>> >>> >>> >>> -- >>> -- >>> Chanaka Fernando >>> Technical Lead >>> WSO2, Inc.; http://wso2.com >>> lean.enterprise.middleware >>> >>> mobile: +94 773337238 >>> Blog : http://soatutorials.blogspot.com >>> LinkedIn:http://www.linkedin.com/pub/chanaka-fernando/19/a20/5b0 >>> Twitter:https://twitter.com/chanakaudaya >>> Wordpress:http://chanakaudaya.wordpress.com >>> >>> >>> >>> >> >> >> -- >> >> Best Regards, >> >> Malaka Silva >> Senior Tech Lead >> M: +94 777 219 791 >> Tel : 94 11 214 5345 >> Fax :94 11 2145300 >> Skype : malaka.sampath.silva >> LinkedIn : http://www.linkedin.com/pub/malaka-silva/6/33/77 >> Blog : http://mrmalakasilva.blogspot.com/ >> >> WSO2, Inc. >> lean . enterprise . middleware >> http://www.wso2.com/ >> http://www.wso2.com/about/team/malaka-silva/ >> <http://wso2.com/about/team/malaka-silva/> >> >> Save a tree -Conserve nature & Save the world for your future. Print this >> email only if it is absolutely necessary. >> > > > > -- > <dev-requ...@wso2.org> > Keerthika Mahendralingam > Associate Software Engineer > Mobile :+94 (0) 776 121144 > keerth...@wso2.com > WSO2, Inc. > lean . enterprise . middleware > -- <dev-requ...@wso2.org> Keerthika Mahendralingam Associate Software Engineer Mobile :+94 (0) 776 121144 keerth...@wso2.com WSO2, Inc. lean . enterprise . middleware
_______________________________________________ Dev mailing list Dev@wso2.org http://wso2.org/cgi-bin/mailman/listinfo/dev