AutoIt Requires Chilkat v11.0.0+
AutoIt
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 AutoIt Downloads
Local $bSuccess = False
; Assumes Chilkat is unlocked. See Global Unlock Sample.
$bSuccess = False
$oHttp = ObjCreate("Chilkat.Http")
$oHttp.RequireSslCertVerify = True
; Supply your API key from protected configuration; AuthToken adds the Bearer prefix.
$oHttp.AuthToken = "SENDGRID_API_KEY"
$oResp = ObjCreate("Chilkat.HttpResponse")
; SetUrlVar encodes the raw address as a URL component, including the plus sign.
$oHttp.SetUrlVar("address","avery+orders@example.com")
$bSuccess = $oHttp.HttpNoBody("GET","https://api.sendgrid.com/v3/suppression/bounces/{$address}",$oResp)
If ($bSuccess <> True) Then
If ($oResp.StatusCode = 0) Then
ConsoleWrite($oHttp.LastErrorText & @CRLF)
Else
ConsoleWrite("HTTP " & $oResp.StatusCode & ": " & $oResp.BodyStr & @CRLF)
EndIf
Exit
EndIf
If ($oResp.StatusCode <> 200) Then
ConsoleWrite("HTTP " & $oResp.StatusCode & ": " & $oResp.BodyStr & @CRLF)
Exit
EndIf
$oRows = ObjCreate("Chilkat.JsonArray")
$bSuccess = $oRows.Load($oResp.BodyStr)
If ($bSuccess <> True) Then
ConsoleWrite("Unexpected response: expected JSON." & @CRLF)
Exit
EndIf
If ($oRows.Size = 0) Then
ConsoleWrite("No bounce record for this address." & @CRLF)
Exit
EndIf
$oRow = ObjCreate("Chilkat.JsonObject")
Local $i = 0
While ($i < $oRows.Size)
$oRows.ObjectAt2($i,$oRow)
ConsoleWrite($oRow.StringOf("email") & ": " & $oRow.StringOf("status") & " " & $oRow.StringOf("reason") & @CRLF)
$i = $i + 1
Wend