PowerBuilder Requires Chilkat v11.0.0+
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
long li_Success
oleobject loo_Http
oleobject loo_Resp
oleobject loo_Rows
oleobject loo_Row
long i
li_Success = 0
// Assumes Chilkat is unlocked. See Global Unlock Sample.
li_Success = 0
loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Http.RequireSslCertVerify = 1
// Supply your API key from protected configuration; AuthToken adds the Bearer prefix.
loo_Http.AuthToken = "SENDGRID_API_KEY"
loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")
// SetUrlVar encodes the raw address as a URL component, including the plus sign.
loo_Http.SetUrlVar("address","avery+orders@example.com")
li_Success = loo_Http.HttpNoBody("GET","https://api.sendgrid.com/v3/suppression/bounces/{$address}",loo_Resp)
if li_Success <> 1 then
if loo_Resp.StatusCode = 0 then
Write-Debug loo_Http.LastErrorText
else
Write-Debug "HTTP " + string(loo_Resp.StatusCode) + ": " + loo_Resp.BodyStr
end if
destroy loo_Http
destroy loo_Resp
return
end if
if loo_Resp.StatusCode <> 200 then
Write-Debug "HTTP " + string(loo_Resp.StatusCode) + ": " + loo_Resp.BodyStr
destroy loo_Http
destroy loo_Resp
return
end if
loo_Rows = create oleobject
li_rc = loo_Rows.ConnectToNewObject("Chilkat.JsonArray")
li_Success = loo_Rows.Load(loo_Resp.BodyStr)
if li_Success <> 1 then
Write-Debug "Unexpected response: expected JSON."
destroy loo_Http
destroy loo_Resp
destroy loo_Rows
return
end if
if loo_Rows.Size = 0 then
Write-Debug "No bounce record for this address."
destroy loo_Http
destroy loo_Resp
destroy loo_Rows
return
end if
loo_Row = create oleobject
li_rc = loo_Row.ConnectToNewObject("Chilkat.JsonObject")
i = 0
do while (i < loo_Rows.Size)
loo_Rows.ObjectAt2(i,loo_Row)
Write-Debug loo_Row.StringOf("email") + ": " + loo_Row.StringOf("status") + " " + loo_Row.StringOf("reason")
i = i + 1
loop
destroy loo_Http
destroy loo_Resp
destroy loo_Rows
destroy loo_Row