CkPython Requires Chilkat v11.0.0+
CkPython
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 CkPython Downloads
import sys
import chilkat
success = False
# Assumes Chilkat is unlocked. See Global Unlock Sample.
success = False
http = chilkat.CkHttp()
http.put_RequireSslCertVerify(True)
# Supply your API key from protected configuration; AuthToken adds the Bearer prefix.
http.put_AuthToken("SENDGRID_API_KEY")
resp = chilkat.CkHttpResponse()
# SetUrlVar encodes the raw address as a URL component, including the plus sign.
http.SetUrlVar("address","avery+orders@example.com")
success = http.HttpNoBody("GET","https://api.sendgrid.com/v3/suppression/bounces/{$address}",resp)
if (success != True):
if (resp.get_StatusCode() == 0):
print(http.lastErrorText())
else:
print("HTTP " + str(resp.get_StatusCode()) + ": " + resp.bodyStr())
sys.exit()
if (resp.get_StatusCode() != 200):
print("HTTP " + str(resp.get_StatusCode()) + ": " + resp.bodyStr())
sys.exit()
rows = chilkat.CkJsonArray()
success = rows.Load(resp.bodyStr())
if (success != True):
print("Unexpected response: expected JSON.")
sys.exit()
if (rows.get_Size() == 0):
print("No bounce record for this address.")
sys.exit()
row = chilkat.CkJsonObject()
i = 0
while (i < rows.get_Size()) :
rows.ObjectAt2(i,row)
print(row.stringOf("email") + ": " + row.stringOf("status") + " " + row.stringOf("reason"))
i = i + 1