【问题标题】:total items not get in response sendgrid nodejs Api总项目没有得到响应 sendgrid nodejs Api
【发布时间】: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


【解决方案1】:

遗憾的是,SendGrid 似乎没有在您使用的 API 中提供收件人数量。但是,他们提供了一个单独的 API 调用,您可以从中获取收件人总数:

GET /v3/contactdb/lists/{list_id}

例如:

var request = sg.emptyRequest();

request.queryParams["list_id"] = '1';
request.method = 'GET';
request.path = '/v3/contactdb/lists/{list_id}';

sg.API(request, function(error, response) {
  console.log(response.statusCode);
  console.log(response.body);
  console.log(response.body.id); // The list id
  console.log(response.body.name); // The list name
  console.log(response.body.recipient_count); // The count of all recipients of this list
  console.log(response.headers);
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-29
    • 2020-02-09
    • 1970-01-01
    • 2023-02-23
    • 1970-01-01
    相关资源
    最近更新 更多