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

AutoIt
Local $bSuccess = False

;  Assumes Chilkat is unlocked. See Global Unlock Sample.
$oHttp = ObjCreate("Chilkat.Http")
$oHttp.RequireSslCertVerify = True
$oHttp.BasicAuth = True
;  Load the owning Account SID and an API key from application configuration.
Local $sAccountSid = "YOUR_ACCOUNT_SID"
$oHttp.Login = "YOUR_API_KEY_SID"
$oHttp.Password = "YOUR_API_KEY_SECRET"
$oUrl = ObjCreate("Chilkat.StringBuilder")
$oUrl.Append("https://api.twilio.com/2010-04-01/Accounts/")
$oUrl.Append($sAccountSid)
$oUrl.Append("/Messages.json")
$oUrl.Append("?PageSize=50")
$oResp = ObjCreate("Chilkat.HttpResponse")
$oReply = ObjCreate("Chilkat.JsonObject")
Local $iTotal = 0
Local $bMore = True
While ($bMore = True)
    $bSuccess = $oHttp.HttpNoBody("GET",$oUrl.GetAsString(),$oResp)
    If ($oResp.StatusCode = 0) Then
        ConsoleWrite($oHttp.LastErrorText & @CRLF)
        Exit
    EndIf

Local $bParsed = $oReply.Load($oResp.BodyStr)
    If (($bSuccess <> True) Or ($oResp.StatusCode <> 200)) Then
        ConsoleWrite("HTTP " & $oResp.StatusCode & @CRLF)
        If (($bParsed = True) And ($oReply.HasMember("code") = True)) Then
            ConsoleWrite("Twilio error " & $oReply.IntOf("code") & ": " & $oReply.StringOf("message") & @CRLF)
        EndIf

        Exit
    EndIf

    If ($bParsed <> True) Then
        ConsoleWrite("Expected a JSON response." & @CRLF)
        Exit
    EndIf

    If ($oReply.JsonTypeOf("messages") <> 4) Then
        ConsoleWrite("Expected a messages array." & @CRLF)
        Exit
    EndIf

Local $iCount = $oReply.SizeOfArray("messages")
Local $i = 0
    While ($i < $iCount)
        $oReply.I = $i
        ConsoleWrite($oReply.StringOf("messages[i].sid") & "  " & $oReply.StringOf("messages[i].direction") & "  " & $oReply.StringOf("messages[i].status") & @CRLF)
        $i = $i + 1
    Wend
    $iTotal = $iTotal + $iCount
    ;  Twilio supplies a relative URI with the cursor and returns null on the last page.
    If ($oReply.IsNullOf("next_page_uri") = True) Then
        $bMore = False
    Else
        If ($oReply.JsonTypeOf("next_page_uri") <> 1) Then
            ConsoleWrite("Expected a next-page URI or null." & @CRLF)
            Exit
        EndIf

        $oUrl.SetString("https://api.twilio.com")
        $oUrl.Append($oReply.StringOf("next_page_uri"))
    EndIf

Wend
ConsoleWrite("Messages found: " & $iTotal & @CRLF)