JavaScript Requires Chilkat v11.0.0+
JavaScript
SendGrid: Look up a bounced email address
See more SendGrid Examples
Look up a recipient on the bounce suppression list without changing it. SendGrid returns an array. An empty array means there is no bounce record for this lookup; it does not prove a particular message reached the inbox.
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat
v11.4.0 or greater.
var success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
success = false;
var http = new CkHttp();
http.RequireSslCertVerify = true;
// Supply your API key from protected configuration; AuthToken adds the Bearer prefix.
http.AuthToken = "SENDGRID_API_KEY";
var resp = new CkHttpResponse();
// SetUrlVar encodes the raw address as a URL component, including the plus sign.
http.SetUrlVar("address","avery+orders@example.com");
success = http.HttpNoBody("GET","https://api.sendgrid.com/v3/suppression/bounces/{$address}",resp);
if (success !== true) {
if (resp.StatusCode == 0) {
console.log(http.LastErrorText);
}
else {
console.log("HTTP " + resp.StatusCode + ": " + resp.BodyStr);
}
return;
}
if (resp.StatusCode !== 200) {
console.log("HTTP " + resp.StatusCode + ": " + resp.BodyStr);
return;
}
var rows = new CkJsonArray();
success = rows.Load(resp.BodyStr);
if (success !== true) {
console.log("Unexpected response: expected JSON.");
return;
}
if (rows.Size == 0) {
console.log("No bounce record for this address.");
return;
}
var row = new CkJsonObject();
var i = 0;
while ((i < rows.Size)) {
rows.ObjectAt2(i,row);
console.log(row.StringOf("email") + ": " + row.StringOf("status") + " " + row.StringOf("reason"));
i = i+1;
}