VB.NET Requires Chilkat v11.0.0+
VB.NET
List Twilio message history
See more Twilio Examples
List inbound and outbound messages, newest sent date first. Print the Message SID, direction, and status so you can distinguish incoming messages from outbound submissions and see their latest state.
Each response contains a messages array and a next_page_uri. Follow that URI until it is null. PageSize limits one response. Use credentials for the account whose history you want to read.
Chilkat VB.NET Downloads
Dim success As Boolean = False
' Assumes Chilkat is unlocked. See Global Unlock Sample.
Dim http As New Chilkat.Http
http.RequireSslCertVerify = True
http.BasicAuth = True
' Load the owning Account SID and an API key from application configuration.
Dim accountSid As String = "YOUR_ACCOUNT_SID"
http.Login = "YOUR_API_KEY_SID"
http.Password = "YOUR_API_KEY_SECRET"
Dim url As New Chilkat.StringBuilder
url.Append("https://api.twilio.com/2010-04-01/Accounts/")
url.Append(accountSid)
url.Append("/Messages.json")
url.Append("?PageSize=50")
Dim resp As New Chilkat.HttpResponse
Dim reply As New Chilkat.JsonObject
Dim total As Integer = 0
Dim more As Boolean = True
While (more = True)
success = http.HttpNoBody("GET",url.GetAsString(),resp)
If (resp.StatusCode = 0) Then
Debug.WriteLine(http.LastErrorText)
Exit Sub
End If
Dim parsed As Boolean = reply.Load(resp.BodyStr)
If ((success <> True) Or (resp.StatusCode <> 200)) Then
Debug.WriteLine("HTTP " & resp.StatusCode)
If ((parsed = True) And (reply.HasMember("code") = True)) Then
Debug.WriteLine("Twilio error " & reply.IntOf("code") & ": " & reply.StringOf("message"))
End If
Exit Sub
End If
If (parsed <> True) Then
Debug.WriteLine("Expected a JSON response.")
Exit Sub
End If
If (reply.JsonTypeOf("messages") <> 4) Then
Debug.WriteLine("Expected a messages array.")
Exit Sub
End If
Dim count As Integer = reply.SizeOfArray("messages")
Dim i As Integer = 0
While (i < count)
reply.I = i
Debug.WriteLine(reply.StringOf("messages[i].sid") & " " & reply.StringOf("messages[i].direction") & " " & reply.StringOf("messages[i].status"))
i = i + 1
End While
total = total + count
' Twilio supplies a relative URI with the cursor and returns null on the last page.
If (reply.IsNullOf("next_page_uri") = True) Then
more = False
Else
If (reply.JsonTypeOf("next_page_uri") <> 1) Then
Debug.WriteLine("Expected a next-page URI or null.")
Exit Sub
End If
url.SetString("https://api.twilio.com")
url.Append(reply.StringOf("next_page_uri"))
End If
End While
Debug.WriteLine("Messages found: " & total)