Sample code for 30+ languages & platforms
PowerBuilder

Twilio List Log Messages

See more Twilio Examples

Fetch the log containing information about SMS messages previously sent (or failed to be sent).

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_SbResponseBody
oleobject loo_Json
integer li_RespStatusCode
string ls_Account_sid
string ls_Api_version
string ls_Body
string ls_Date_created
string ls_Date_sent
string ls_Date_updated
string ls_Direction
string ls_Error_code
string ls_Error_message
string ls_From
string ls_Messaging_service_sid
string ls_Num_media
string ls_Num_segments
string ls_Price
string ls_Price_unit
string ls_Sid
string ls_Status
string ls_Subresource_urisMedia
string ls_Subresource_urisFeedback
string ls_V_to
integer li_End
string ls_First_page_uri
string ls_Next_page_uri
integer li_Page
integer li_Page_size
string ls_Previous_page_uri
integer li_Start
string ls_Uri
integer i
integer li_Count_i

li_Success = 0

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// Implements the following CURL command:

// curl -X GET 'https://api.twilio.com/2010-04-01/Accounts/TWILIO_ACCOUNT_SID/Messages.json?PageSize=20' \
// -u TWILIO_ACCOUNT_SID:TWILIO_AUTH_TOKEN

// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code

loo_Http.Login = "TWILIO_ACCOUNT_SID"
loo_Http.Password = "TWILIO_AUTH_TOKEN"

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_Http.QuickGetSb("https://api.twilio.com/2010-04-01/Accounts/TWILIO_ACCOUNT_SID/Messages.json?PageSize=20",loo_SbResponseBody)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_SbResponseBody
    return
end if

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

loo_Json.LoadSb(loo_SbResponseBody)
loo_Json.EmitCompact = 0

Write-Debug "Response Body:"
Write-Debug loo_Json.Emit()

li_RespStatusCode = loo_Http.LastStatus
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Http.LastHeader
    Write-Debug "Failed."
    destroy loo_Http
    destroy loo_SbResponseBody
    destroy loo_Json
    return
end if

// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)

// {
//   "end": 1,
//   "first_page_uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages.json?To=%2B123456789&From=%2B987654321&DateSent%3E=2008-01-02&PageSize=2&Page=0",
//   "next_page_uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages.json?To=%2B123456789&From=%2B987654321&DateSent%3E=2008-01-02&PageSize=2&Page=1&PageToken=PAMMc26223853f8c46b4ab7dfaa6abba0a26",
//   "page": 0,
//   "page_size": 2,
//   "previous_page_uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages.json?To=%2B123456789&From=%2B987654321&DateSent%3E=2008-01-02&PageSize=2&Page=0",
//   "messages": [
//     {
//       "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
//       "api_version": "2010-04-01",
//       "body": "testing",
//       "date_created": "Fri, 24 May 2019 17:44:46 +0000",
//       "date_sent": "Fri, 24 May 2019 17:44:50 +0000",
//       "date_updated": "Fri, 24 May 2019 17:44:50 +0000",
//       "direction": "outbound-api",
//       "error_code": null,
//       "error_message": null,
//       "from": "+12019235161",
//       "messaging_service_sid": null,
//       "num_media": "0",
//       "num_segments": "1",
//       "price": "-0.00750",
//       "price_unit": "USD",
//       "sid": "SMded05904ccb347238880ca9264e8fe1c",
//       "status": "sent",
//       "subresource_uris": {
//         "media": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/SMded05904ccb347238880ca9264e8fe1c/Media.json",
//         "feedback": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/SMded05904ccb347238880ca9264e8fe1c/Feedback.json"
//       },
//       "to": "+18182008801",
//       "uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/SMded05904ccb347238880ca9264e8fe1c.json"
//     },
//     {
//       "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
//       "api_version": "2010-04-01",
//       "body": "look mom I have media!",
//       "date_created": "Fri, 24 May 2019 17:44:46 +0000",
//       "date_sent": "Fri, 24 May 2019 17:44:49 +0000",
//       "date_updated": "Fri, 24 May 2019 17:44:49 +0000",
//       "direction": "inbound",
//       "error_code": 30004,
//       "error_message": "Message blocked",
//       "from": "+12019235161",
//       "messaging_service_sid": null,
//       "num_media": "3",
//       "num_segments": "1",
//       "price": "-0.00750",
//       "price_unit": "USD",
//       "sid": "MMc26223853f8c46b4ab7dfaa6abba0a26",
//       "status": "received",
//       "subresource_uris": {
//         "media": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMc26223853f8c46b4ab7dfaa6abba0a26/Media.json",
//         "feedback": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMc26223853f8c46b4ab7dfaa6abba0a26/Feedback.json"
//       },
//       "to": "+18182008801",
//       "uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMc26223853f8c46b4ab7dfaa6abba0a26.json"
//     }
//   ],
//   "start": 0,
//   "uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages.json?To=%2B123456789&From=%2B987654321&DateSent%3E=2008-01-02&PageSize=2&Page=0"
// }

// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON

li_End = loo_Json.IntOf("end")
ls_First_page_uri = loo_Json.StringOf("first_page_uri")
ls_Next_page_uri = loo_Json.StringOf("next_page_uri")
li_Page = loo_Json.IntOf("page")
li_Page_size = loo_Json.IntOf("page_size")
ls_Previous_page_uri = loo_Json.StringOf("previous_page_uri")
li_Start = loo_Json.IntOf("start")
ls_Uri = loo_Json.StringOf("uri")
i = 0
li_Count_i = loo_Json.SizeOfArray("messages")
do while i < li_Count_i
    loo_Json.I = i
    ls_Account_sid = loo_Json.StringOf("messages[i].account_sid")
    ls_Api_version = loo_Json.StringOf("messages[i].api_version")
    ls_Body = loo_Json.StringOf("messages[i].body")
    ls_Date_created = loo_Json.StringOf("messages[i].date_created")
    ls_Date_sent = loo_Json.StringOf("messages[i].date_sent")
    ls_Date_updated = loo_Json.StringOf("messages[i].date_updated")
    ls_Direction = loo_Json.StringOf("messages[i].direction")
    ls_Error_code = loo_Json.StringOf("messages[i].error_code")
    ls_Error_message = loo_Json.StringOf("messages[i].error_message")
    ls_From = loo_Json.StringOf("messages[i].from")
    ls_Messaging_service_sid = loo_Json.StringOf("messages[i].messaging_service_sid")
    ls_Num_media = loo_Json.StringOf("messages[i].num_media")
    ls_Num_segments = loo_Json.StringOf("messages[i].num_segments")
    ls_Price = loo_Json.StringOf("messages[i].price")
    ls_Price_unit = loo_Json.StringOf("messages[i].price_unit")
    ls_Sid = loo_Json.StringOf("messages[i].sid")
    ls_Status = loo_Json.StringOf("messages[i].status")
    ls_Subresource_urisMedia = loo_Json.StringOf("messages[i].subresource_uris.media")
    ls_Subresource_urisFeedback = loo_Json.StringOf("messages[i].subresource_uris.feedback")
    ls_V_to = loo_Json.StringOf("messages[i].to")
    ls_Uri = loo_Json.StringOf("messages[i].uri")
    i = i + 1
loop


destroy loo_Http
destroy loo_SbResponseBody
destroy loo_Json