E9.2 Consuming REST API with multiple pages

Glenn McClenny

Member
A 3rd party API returns data in pages of 100 records, meaning if there would be 500 records in a json response, the rest API would have to be called 5 times passing the appropriate next page number. When the API is call, the end of the json response has the page info in it.

"resultInfo": {
"page": 1,
"perPage": 100,
"totalPages": 27,
"count": 100,
"totalCount": 2633,
"previousPage": null,
"nextPage": "/api/XXXX?PageSize=100&page=2"
},

How can I "loop" through the pages to update the appropriate JDE tables with all the records?
 
Easiest would be to process 1 page of records at a time. You then build a "simple" recursive orch where you take 1 page of api results, process those in JDE, and then check the results to see if nextPage is populated. If it is, then call the same orch recursively.

The recursive call needs to be a local AIS REST call rather than an orch component for it to work properly in P98220W and other places incl export/import. At least on my version :) Also you'll want to put in a hard count limit on your recursions just in case you get into an infinite loop or process more recs than you want.

A bit more difficult but not crazy would be to recursively call the API while "accumulating" your dataset, and then once the recursion is done you process the entire dataset once. It's a bit more dangerous IMO.

I'll be presenting at blueprint including a recursive orch that I'll be giving away if you're going, otherwise I'll hand it out here after conference.
 
最简单的方法是一次处理 1 页记录。然后,您构建一个 “简单” 递归 ORCH,其中获取 1 页 api 结果,在 JDE 中处理这些结果,然后检查结果以查看是否填充了 nextPage。如果是,则递归调用同一个 orch。

递归调用需要是本地 AIS REST 调用而不是 orch 组件,以便它在 P98220W 和其他地方正常工作,包括 export/import。至少在我的版本上,您需要对递归设置硬性计数限制,以防万一您进入无限循环或处理的推荐数量超过您想要的。:)

稍微困难一点但并不疯狂的是,在“积累”数据集的同时递归调用 API,然后在递归完成后处理整个数据集一次。这有点危险。

我将在 Blueprint 上展示一个递归 orch,如果你要去的话,我会把它送出去,否则我会在会议结束后在这里分发它。
为什么我使用的官方示例中没有链接的 JSON 返回?
 
Back
Top