Sample code for 30+ languages & platforms
Classic ASP 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 Classic ASP Downloads

Classic ASP
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0

'  Assumes Chilkat is unlocked. See Global Unlock Sample.
set http = Server.CreateObject("Chilkat.Http")
http.RequireSslCertVerify = 1
http.BasicAuth = 1
'  Load the owning Account SID and an API key from application configuration.
accountSid = "YOUR_ACCOUNT_SID"
http.Login = "YOUR_API_KEY_SID"
http.Password = "YOUR_API_KEY_SECRET"
set url = Server.CreateObject("Chilkat.StringBuilder")
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")
set resp = Server.CreateObject("Chilkat.HttpResponse")
set reply = Server.CreateObject("Chilkat.JsonObject")
total = 0
more = 1
Do While (more = 1)
    success = http.HttpNoBody("GET",url.GetAsString(),resp)
    If (resp.StatusCode = 0) Then
        Response.Write "<pre>" & Server.HTMLEncode( http.LastErrorText) & "</pre>"
        Response.End
    End If

    parsed = reply.Load(resp.BodyStr)
    If ((success <> 1) Or (resp.StatusCode <> 200)) Then
        Response.Write "<pre>" & Server.HTMLEncode( "HTTP " & resp.StatusCode) & "</pre>"
        If ((parsed = 1) And (reply.HasMember("code") = 1)) Then
            Response.Write "<pre>" & Server.HTMLEncode( "Twilio error " & reply.IntOf("code") & ": " & reply.StringOf("message")) & "</pre>"
        End If

        Response.End
    End If

    If (parsed <> 1) Then
        Response.Write "<pre>" & Server.HTMLEncode( "Expected a JSON response.") & "</pre>"
        Response.End
    End If

    If (reply.JsonTypeOf("messages") <> 4) Then
        Response.Write "<pre>" & Server.HTMLEncode( "Expected a messages array.") & "</pre>"
        Response.End
    End If

    count = reply.SizeOfArray("messages")
    i = 0
    Do While (i < count)
        reply.I = i
        Response.Write "<pre>" & Server.HTMLEncode( reply.StringOf("messages[i].sid") & "  " & reply.StringOf("messages[i].direction") & "  " & reply.StringOf("messages[i].status")) & "</pre>"
        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
            Response.Write "<pre>" & Server.HTMLEncode( "Expected a next-page URI or null.") & "</pre>"
            Response.End
        End If

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

Loop
Response.Write "<pre>" & Server.HTMLEncode( "Messages found: " & total) & "</pre>"

%>
</body>
</html>