VBScript Requires Chilkat v11.0.0+
VBScript
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 VBScript Downloads
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)
success = 0
' Assumes Chilkat is unlocked. See Global Unlock Sample.
set http = 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 = 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 = CreateObject("Chilkat.HttpResponse")
set reply = CreateObject("Chilkat.JsonObject")
total = 0
more = 1
Do While (more = 1)
success = http.HttpNoBody("GET",url.GetAsString(),resp)
If (resp.StatusCode = 0) Then
outFile.WriteLine(http.LastErrorText)
WScript.Quit
End If
parsed = reply.Load(resp.BodyStr)
If ((success <> 1) Or (resp.StatusCode <> 200)) Then
outFile.WriteLine("HTTP " & resp.StatusCode)
If ((parsed = 1) And (reply.HasMember("code") = 1)) Then
outFile.WriteLine("Twilio error " & reply.IntOf("code") & ": " & reply.StringOf("message"))
End If
WScript.Quit
End If
If (parsed <> 1) Then
outFile.WriteLine("Expected a JSON response.")
WScript.Quit
End If
If (reply.JsonTypeOf("messages") <> 4) Then
outFile.WriteLine("Expected a messages array.")
WScript.Quit
End If
count = reply.SizeOfArray("messages")
i = 0
Do While (i < count)
reply.I = i
outFile.WriteLine(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
outFile.WriteLine("Expected a next-page URI or null.")
WScript.Quit
End If
success = url.SetString("https://api.twilio.com")
success = url.Append(reply.StringOf("next_page_uri"))
End If
Loop
outFile.WriteLine("Messages found: " & total)
outFile.Close