Visual Basic 6.0 Requires Chilkat v11.0.0+
Visual Basic 6.0
SendGrid: Report daily requests, deliveries, bounces, and blocks
See more SendGrid Examples
Retrieve seven completed UTC dates and print one row per date. The counts are account-level aggregates; a day’s delivered count does not identify which messages sent that day were delivered.
Chilkat Visual Basic 6.0 Downloads
Dim success As Long
success = 0
' Assumes Chilkat is unlocked. See Global Unlock Sample.
success = 0
Dim http As New ChilkatHttp
http.RequireSslCertVerify = 1
' Supply your API key from protected configuration; AuthToken adds the Bearer prefix.
http.AuthToken = "SENDGRID_API_KEY"
Dim resp As New ChilkatHttpResponse
Dim day As New CkDateTime
success = day.SetFromCurrentSystemTime()
success = day.AddDays(-1)
success = http.SetUrlVar("end",day.GetAsIso8601("YYYY-MM-DD",0))
success = day.AddDays(-6)
success = http.SetUrlVar("start",day.GetAsIso8601("YYYY-MM-DD",0))
success = http.HttpNoBody("GET","https://api.sendgrid.com/v3/stats?start_date={$start}&end_date={$end}&aggregated_by=day",resp)
If (success <> 1) Then
If (resp.StatusCode = 0) Then
Debug.Print http.LastErrorText
Else
Debug.Print "HTTP " & resp.StatusCode & ": " & resp.BodyStr
End If
Exit Sub
End If
If (resp.StatusCode <> 200) Then
Debug.Print "HTTP " & resp.StatusCode & ": " & resp.BodyStr
Exit Sub
End If
Dim days As New ChilkatJsonArray
success = days.Load(resp.BodyStr)
If (success <> 1) Then
Debug.Print "Unexpected response: expected JSON."
Exit Sub
End If
Debug.Print "Date,Requests,Delivered,Bounces,Blocks"
Dim row As New ChilkatJsonObject
Dim i As Long
i = 0
Do While (i < days.Size)
success = days.ObjectAt2(i,row)
Debug.Print row.StringOf("date") & "," & row.IntOf("stats[0].metrics.requests") & "," & row.IntOf("stats[0].metrics.delivered") & "," & row.IntOf("stats[0].metrics.bounces") _
& "," & row.IntOf("stats[0].metrics.blocks")
i = i + 1
Loop