DataFlex Requires Chilkat v11.0.0+
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoHttp
Variant vResp
Handle hoResp
Variant vRow
s Handle hoRows
Variant vRow
Handle hoRow
Integer i
String sTemp1
String sTemp2
String sTemp3
Integer iTemp1
Move False To iSuccess
// Assumes Chilkat is unlocked. See Global Unlock Sample.
Move False To iSuccess
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
Set ComRequireSslCertVerify Of hoHttp To True
// Supply your API key from protected configuration; AuthToken adds the Bearer prefix.
Set ComAuthToken Of hoHttp To "SENDGRID_API_KEY"
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
If (Not(IsComObjectCreated(hoResp))) Begin
Send CreateComObject of hoResp
End
// SetUrlVar encodes the raw address as a URL component, including the plus sign.
Get ComSetUrlVar Of hoHttp "address" "avery+orders@example.com" To iSuccess
Get pvComObject of hoResp to vResp
Get ComHttpNoBody Of hoHttp "GET" "https://api.sendgrid.com/v3/suppression/bounces/{$address}" vResp To iSuccess
If (iSuccess <> True) Begin
Get ComStatusCode Of hoResp To iTemp1
If (iTemp1 = 0) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
End
Else Begin
Get ComStatusCode Of hoResp To iTemp1
Get ComBodyStr Of hoResp To sTemp1
Showln "HTTP " iTemp1 ": " sTemp1
End
Procedure_Return
End
Get ComStatusCode Of hoResp To iTemp1
If (iTemp1 <> 200) Begin
Get ComStatusCode Of hoResp To iTemp1
Get ComBodyStr Of hoResp To sTemp1
Showln "HTTP " iTemp1 ": " sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatJsonArray)) To hoRows
If (Not(IsComObjectCreated(hoRows))) Begin
Send CreateComObject of hoRows
End
Get ComBodyStr Of hoResp To sTemp1
Get ComLoad Of hoRows sTemp1 To iSuccess
If (iSuccess <> True) Begin
Showln "Unexpected response: expected JSON."
Procedure_Return
End
Get ComSize Of hoRows To iTemp1
If (iTemp1 = 0) Begin
Showln "No bounce record for this address."
Procedure_Return
End
Get Create (RefClass(cComChilkatJsonObject)) To hoRow
If (Not(IsComObjectCreated(hoRow))) Begin
Send CreateComObject of hoRow
End
Move 0 To i
While (i < (ComSize(hoRows)))
Get pvComObject of hoRow to vRow
Get ComObjectAt2 Of hoRows i vRow To iSuccess
Get ComStringOf Of hoRow "email" To sTemp1
Get ComStringOf Of hoRow "status" To sTemp2
Get ComStringOf Of hoRow "reason" To sTemp3
Showln sTemp1 ": " sTemp2 " " sTemp3
Move (i + 1) To i
Loop
End_Procedure