4

检索列表中的所有收件人:-

`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 中工作,但我没有得到总项目参数作为响应。

4

1 回答 1

1

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

获取 /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);
});
于 2017-02-20T13:28:09.653 回答