使用 Shipment.all 和 Tracker.all 的 Nodejs 分页
Nodejs Pagination using Shipment.all and Tracker.all
Appolgies 我对 Nodejs 和编程还很陌生,所以长话短说:
使用 Easypost Nodejs API,我需要每天使用我的 Nodejs/express 后端检索所有跟踪状态 3 次。
我以非常低效的方式检索所有跟踪状态时遇到了速率限制'。这是对每个 Shipmentid 的单独调用以获取 Trackingid,然后获取最新状态。我知道非常糟糕。
所以我去看了 Docs 并想,很酷,我会单独做事,获取我的所有包裹 (myDB),然后单独获取所有跟踪器的列表,然后使用发货 ID 进行匹配。
问题...
我是新手
如何使用分页进行多次调用 -> 我的第一个想法是 运行 初始调用以查看是否有多个页面,如果 "has_more" 为真运行 在过去的 2 个月里,我需要多少页就多少次。
下一个问题...我似乎缺少来自 easypost API 的响应中的分页信息。在文档中应该有一个回应
{trackers:[all tracker info here], "has_more": true}
但响应中只有一系列跟踪器。即使我将页面大小设置为 1 或 2...
获取跟踪器列表的当前代码:
.get((req, res) => {
console.log('Recieved - ' + req.method + req.originalUrl)
easyPostAPI.Tracker.all(req.body)
.then( response => {
console.log('Sent - ' + req.method + req.originalUrl)
res.json(response)
})
.catch(err => {
console.log(err)
res.status(400).json(err)
})
})```
hopefully it's not just me getting it wrong.
EasyPost just released a 3.8.0 version of the node library 其中你可以访问 has_more
属性 数组,像这样:
api.Shipment.all({ page_size: 2, ... }).then(shipment => console.log(shipment.has_more))
在@easypost/api v4.0.0 中可能会有更方便的分页方式,但目前,上面的属性应该可以让你分页。
Appolgies 我对 Nodejs 和编程还很陌生,所以长话短说:
使用 Easypost Nodejs API,我需要每天使用我的 Nodejs/express 后端检索所有跟踪状态 3 次。
我以非常低效的方式检索所有跟踪状态时遇到了速率限制'。这是对每个 Shipmentid 的单独调用以获取 Trackingid,然后获取最新状态。我知道非常糟糕。
所以我去看了 Docs 并想,很酷,我会单独做事,获取我的所有包裹 (myDB),然后单独获取所有跟踪器的列表,然后使用发货 ID 进行匹配。
问题...
我是新手
如何使用分页进行多次调用 -> 我的第一个想法是 运行 初始调用以查看是否有多个页面,如果 "has_more" 为真运行 在过去的 2 个月里,我需要多少页就多少次。
下一个问题...我似乎缺少来自 easypost API 的响应中的分页信息。在文档中应该有一个回应
{trackers:[all tracker info here], "has_more": true}
但响应中只有一系列跟踪器。即使我将页面大小设置为 1 或 2...
获取跟踪器列表的当前代码:
.get((req, res) => {
console.log('Recieved - ' + req.method + req.originalUrl)
easyPostAPI.Tracker.all(req.body)
.then( response => {
console.log('Sent - ' + req.method + req.originalUrl)
res.json(response)
})
.catch(err => {
console.log(err)
res.status(400).json(err)
})
})```
hopefully it's not just me getting it wrong.
EasyPost just released a 3.8.0 version of the node library 其中你可以访问 has_more
属性 数组,像这样:
api.Shipment.all({ page_size: 2, ... }).then(shipment => console.log(shipment.has_more))
在@easypost/api v4.0.0 中可能会有更方便的分页方式,但目前,上面的属性应该可以让你分页。