VBScript Requires Chilkat v11.0.0+
VBScript
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 VBScript Downloads
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)
success = 0
' Assumes Chilkat is unlocked. See Global Unlock Sample.
success = 0
set http = CreateObject("Chilkat.Http")
http.RequireSslCertVerify = 1
' Supply your API key from protected configuration; AuthToken adds the Bearer prefix.
http.AuthToken = "SENDGRID_API_KEY"
set resp = CreateObject("Chilkat.HttpResponse")
' SetUrlVar encodes the raw address as a URL component, including the plus sign.
success = http.SetUrlVar("address","avery+orders@example.com")
success = http.HttpNoBody("GET","https://api.sendgrid.com/v3/suppression/bounces/{$address}",resp)
If (success <> 1) Then
If (resp.StatusCode = 0) Then
outFile.WriteLine(http.LastErrorText)
Else
outFile.WriteLine("HTTP " & resp.StatusCode & ": " & resp.BodyStr)
End If
WScript.Quit
End If
If (resp.StatusCode <> 200) Then
outFile.WriteLine("HTTP " & resp.StatusCode & ": " & resp.BodyStr)
WScript.Quit
End If
set rows = CreateObject("Chilkat.JsonArray")
success = rows.Load(resp.BodyStr)
If (success <> 1) Then
outFile.WriteLine("Unexpected response: expected JSON.")
WScript.Quit
End If
If (rows.Size = 0) Then
outFile.WriteLine("No bounce record for this address.")
WScript.Quit
End If
set row = CreateObject("Chilkat.JsonObject")
i = 0
Do While (i < rows.Size)
success = rows.ObjectAt2(i,row)
outFile.WriteLine(row.StringOf("email") & ": " & row.StringOf("status") & " " & row.StringOf("reason"))
i = i + 1
Loop
outFile.Close