Unicode C++ Requires Chilkat v11.0.0+
Unicode 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 Unicode C++ Downloads
#include <CkHttpW.h>
#include <CkHttpResponseW.h>
#include <CkJsonArrayW.h>
#include <CkJsonObjectW.h>
void ChilkatSample(void)
{
bool success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
success = false;
CkHttpW http;
http.put_RequireSslCertVerify(true);
// Supply your API key from protected configuration; AuthToken adds the Bearer prefix.
http.put_AuthToken(L"SENDGRID_API_KEY");
CkHttpResponseW resp;
// SetUrlVar encodes the raw address as a URL component, including the plus sign.
http.SetUrlVar(L"address",L"avery+orders@example.com");
success = http.HttpNoBody(L"GET",L"https://api.sendgrid.com/v3/suppression/bounces/{$address}",resp);
if (success != true) {
if (resp.get_StatusCode() == 0) {
wprintf(L"%s\n",http.lastErrorText());
}
else {
wprintf(L"HTTP %d: %s\n",resp.get_StatusCode(),resp.bodyStr());
}
return;
}
if (resp.get_StatusCode() != 200) {
wprintf(L"HTTP %d: %s\n",resp.get_StatusCode(),resp.bodyStr());
return;
}
CkJsonArrayW rows;
success = rows.Load(resp.bodyStr());
if (success != true) {
wprintf(L"Unexpected response: expected JSON.\n");
return;
}
if (rows.get_Size() == 0) {
wprintf(L"No bounce record for this address.\n");
return;
}
CkJsonObjectW row;
int i = 0;
while ((i < rows.get_Size())) {
rows.ObjectAt2(i,row);
wprintf(L"%s: %s %s\n",row.stringOf(L"email"),row.stringOf(L"status"),row.stringOf(L"reason"));
i = i + 1;
}
}