2017-02-16 4 views
3

はリスト上のすべての受信者を取得アピnodejs sendgrid応じて取得していない: -

ここ
`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": "[email protected]", 
     "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" 
    } 
}` 

私はリストによるreciepentsリストを呼び出していますid。 ページ設定がこのApiで動作していますが、私は応答で総アイテムのパラメータを取得していません。

+0

私はAPIを見てきましたが、合計アイテムのようなものは見つかりませんでした。そのAPI呼び出しからどのような応答が得られましたか? – Sravan

+0

私の質問の回答を参照 –

+1

あなたは合計アイテムを取得していないので、あなた自身で手動で数えることができます。 'response.body.recipients.length'は合計アイテムを返します – Sravan

答えて

1

SendGridは、悲しいことに、使用しているAPIの受信者の数を提供していないようです。例えば

GET/V3/contactdb /リスト/ {LIST_ID}

:しかし、彼らはあなたが受信者の合計数を取得することができ、そこから別のAPIコールを提供

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); 
});