C++ Requires Chilkat v11.0.0+
C++
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.
Chilkat C++ Downloads
#include <CkHttp.h>
#include <CkHttpResponse.h>
#include <CkJsonArray.h>
#include <CkJsonObject.h>
void ChilkatSample(void)
{
bool success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
success = false;
CkHttp http;
http.put_RequireSslCertVerify(true);
// Supply your API key from protected configuration; AuthToken adds the Bearer prefix.
http.put_AuthToken("SENDGRID_API_KEY");
CkHttpResponse resp;
// 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.get_StatusCode() == 0) {
std::cout << http.lastErrorText() << "\r\n";
}
else {
std::cout << "HTTP " << resp.get_StatusCode() << ": " << resp.bodyStr() << "\r\n";
}
return;
}
if (resp.get_StatusCode() != 200) {
std::cout << "HTTP " << resp.get_StatusCode() << ": " << resp.bodyStr() << "\r\n";
return;
}
CkJsonArray rows;
success = rows.Load(resp.bodyStr());
if (success != true) {
std::cout << "Unexpected response: expected JSON." << "\r\n";
return;
}
if (rows.get_Size() == 0) {
std::cout << "No bounce record for this address." << "\r\n";
return;
}
CkJsonObject row;
int i = 0;
while ((i < rows.get_Size())) {
rows.ObjectAt2(i,row);
std::cout << row.stringOf("email") << ": " << row.stringOf("status") << " " << row.stringOf("reason") << "\r\n";
i = i + 1;
}
}