Objective-C Requires Chilkat v11.0.0+
Objective-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 Objective-C Downloads
#import <CkoHttp.h>
#import <CkoHttpResponse.h>
#import <CkoJsonArray.h>
#import <CkoJsonObject.h>
BOOL success = NO;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
success = NO;
CkoHttp *http = [[CkoHttp alloc] init];
http.RequireSslCertVerify = YES;
// Supply your API key from protected configuration; AuthToken adds the Bearer prefix.
http.AuthToken = @"SENDGRID_API_KEY";
CkoHttpResponse *resp = [[CkoHttpResponse alloc] init];
// SetUrlVar encodes the raw address as a URL component, including the plus sign.
[http SetUrlVar: @"address" value: @"avery+orders@example.com"];
success = [http HttpNoBody: @"GET" url: @"https://api.sendgrid.com/v3/suppression/bounces/{$address}" response: resp];
if (success != YES) {
if ([resp.StatusCode intValue] == 0) {
NSLog(@"%@",http.LastErrorText);
}
else {
NSLog(@"%@%d%@%@",@"HTTP ",[resp.StatusCode intValue],@": ",resp.BodyStr);
}
return;
}
if ([resp.StatusCode intValue] != 200) {
NSLog(@"%@%d%@%@",@"HTTP ",[resp.StatusCode intValue],@": ",resp.BodyStr);
return;
}
CkoJsonArray *rows = [[CkoJsonArray alloc] init];
success = [rows Load: resp.BodyStr];
if (success != YES) {
NSLog(@"%@",@"Unexpected response: expected JSON.");
return;
}
if ([rows.Size intValue] == 0) {
NSLog(@"%@",@"No bounce record for this address.");
return;
}
CkoJsonObject *row = [[CkoJsonObject alloc] init];
int i = 0;
while ((i < [rows.Size intValue])) {
[rows ObjectAt2: [NSNumber numberWithInt: i] jsonObj: row];
NSLog(@"%@%@%@%@%@",[row StringOf: @"email"],@": ",[row StringOf: @"status"],@" ",[row StringOf: @"reason"]);
i = i + 1;
}