Sample code for 30+ languages & platforms
B4X Requires Chilkat v11.0.0+

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.

Retrieve a bounce

Chilkat B4X Downloads

B4X
Dim success As Boolean = False

'  Assumes Chilkat is unlocked. See Global Unlock Sample.
success = False
Dim http As ChilkatHttp
http.Initialize("http")
http.RequireSslCertVerify = True
'  Supply your API key from protected configuration; AuthToken adds the Bearer prefix.
http.AuthToken = "SENDGRID_API_KEY"
Dim resp As ChilkatHttpResponse
resp.Initialize

'  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 Then
    If resp.StatusCode = 0 Then
        Log(http.LastErrorText)
    Else
        Log("HTTP " & resp.StatusCode & ": " & resp.BodyStr)
    End If

    Return
End If

If resp.StatusCode <> 200 Then
    Log("HTTP " & resp.StatusCode & ": " & resp.BodyStr)
    Return
End If


Dim rows As ChilkatJsonArray
rows.Initialize
success = rows.Load(resp.BodyStr)
If success <> True Then
    Log("Unexpected response: expected JSON.")
    Return
End If

If rows.Size = 0 Then
    Log("No bounce record for this address.")
    Return
End If

Dim row As ChilkatJsonObject
row.Initialize
Dim i As Int = 0
Do While (i < rows.Size)
    rows.ObjectAt2(i, row)
    Log(row.StringOf("email") & ": " & row.StringOf("status") & " " & row.StringOf("reason"))
    i = i + 1
Loop