Sample code for 30+ languages & platforms
Visual Basic 6.0 Requires Chilkat v11.0.0+

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.

Twilio Messages API reference

Chilkat Visual Basic 6.0 Downloads

Visual Basic 6.0
Dim success As Long
success = 0

'  Assumes Chilkat is unlocked. See Global Unlock Sample.
Dim http As New ChilkatHttp
http.RequireSslCertVerify = 1
http.BasicAuth = 1
'  Load the owning Account SID and an API key from application configuration.
Dim accountSid As String
accountSid = "YOUR_ACCOUNT_SID"
http.Login = "YOUR_API_KEY_SID"
http.Password = "YOUR_API_KEY_SECRET"
Dim url As New ChilkatStringBuilder
success = url.Append("https://api.twilio.com/2010-04-01/Accounts/")
success = url.Append(accountSid)
success = url.Append("/Messages.json")
success = url.Append("?PageSize=50")
Dim resp As New ChilkatHttpResponse
Dim reply As New ChilkatJsonObject
Dim total As Long
total = 0
Dim more As Long
more = 1
Do While (more = 1)
    success = http.HttpNoBody("GET",url.GetAsString(),resp)
    If (resp.StatusCode = 0) Then
        Debug.Print http.LastErrorText
        Exit Sub
    End If

    Dim parsed As Long
    parsed = reply.Load(resp.BodyStr)
    If ((success <> 1) Or (resp.StatusCode <> 200)) Then
        Debug.Print "HTTP " & resp.StatusCode
        If ((parsed = 1) And (reply.HasMember("code") = 1)) Then
            Debug.Print "Twilio error " & reply.IntOf("code") & ": " & reply.StringOf("message")
        End If

        Exit Sub
    End If

    If (parsed <> 1) Then
        Debug.Print "Expected a JSON response."
        Exit Sub
    End If

    If (reply.JsonTypeOf("messages") <> 4) Then
        Debug.Print "Expected a messages array."
        Exit Sub
    End If

    Dim count As Long
    count = reply.SizeOfArray("messages")
    Dim i As Long
    i = 0
    Do While (i < count)
        reply.I = i
        Debug.Print reply.StringOf("messages[i].sid") & "  " & reply.StringOf("messages[i].direction") & "  " & reply.StringOf("messages[i].status")
        i = i + 1
    Loop
    total = total + count
    '  Twilio supplies a relative URI with the cursor and returns null on the last page.
    If (reply.IsNullOf("next_page_uri") = 1) Then
        more = 0
    Else
        If (reply.JsonTypeOf("next_page_uri") <> 1) Then
            Debug.Print "Expected a next-page URI or null."
            Exit Sub
        End If

        success = url.SetString("https://api.twilio.com")
        success = url.Append(reply.StringOf("next_page_uri"))
    End If

Loop
Debug.Print "Messages found: " & total