【发布时间】:2017-02-16 13:32:07
【问题描述】:
检索列表中的所有收件人:-
`var request = sg.emptyRequest()
request.queryParams["page"] = '1'
request.queryParams["page_size"] = '1'
request.queryParams["list_id"] = '1'
request.method = 'GET'
request.path = '/v3/contactdb/lists/{list_id}/recipients'
sg.API(request, function (error, response) {
console.log(response.statusCode)
console.log(response.body)
console.log(response.headers)
});`
这是我的 Api 响应:-
`{
"statusCode": 200,
"body": {
"recipients": [
{
"created_at": 1486990474,
"email": "jones2@example.com",
"first_name": null,
"id": "am9uZXMyQGV4YW1wbGUuY29t",
"last_clicked": null,
"last_emailed": null,
"last_name": "tyutyut",
"last_opened": null,
"updated_at": 1486990474
}
]
},
"headers": {
"server": "nginx",
"date": "Mon, 20 Feb 2017 07:11:31 GMT",
"content-type": "application/json",
"content-length": "1052",
"connection": "close",
"access-control-allow-methods": "HEAD, GET, PUT, POST, DELETE,OPTIONS,PATCH",
"access-control-max-age": "21600",
"access-control-expose-headers": "Link",
"access-control-allow-origin": "*",
"x-content-type-options": "nosniff",
"strict-transport-security": "max-age=31536000",
"x-ratelimit-remaining": "0",
"x-ratelimit-limit": "1",
"x-ratelimit-reset": "1487574692",
"powered-by": "Mako"
}
}`
我正在按列表 ID 调用收件人列表。 分页在这个 Api 中工作,但我没有得到总项目参数作为响应。
【问题讨论】:
-
我已经浏览了 API,但没有找到类似总项目的任何内容,您从该 API 调用得到什么响应?
-
查看我的问题中的回复
-
因为你没有得到总数,你可以自己手动统计,
response.body.recipients.length给你总数 -
那么我将不得不在我这边获取所有列表并管理分页。这不是一个合适的解决方案
-
好的,我想你可以单独调用
request.path = '/v3/contactdb/lists/{list_id}/recipients/count'来获取记录的数量。来源github.com/sendgrid/sendgrid-nodejs/blob/master/USAGE.md
标签: node.js sendgrid sendgrid-api-v3