PowerBuilder / Twilio Messaging / SMS / List all messages sent from your Twilio number
Back to Collection Items
integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_QueryParams
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
oleobject loo_Date_created
oleobject loo_Date_sent
oleobject loo_Date_updated
string ls_Account_sid
string ls_Api_version
string ls_Body
string ls_Direction
integer li_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_V_to
integer li_V_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
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
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
loo_Http.BasicAuth = 1
loo_Http.Login = "{{TWILIO_ACCOUNT_SID}}"
loo_Http.Password = "{{TWILIO_AUTH_TOKEN}}"
loo_QueryParams = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_QueryParams.ConnectToNewObject("Chilkat.JsonObject")
loo_QueryParams.UpdateString("From","{{TWILIO_PHONE_NUMBER}}")
loo_Resp = loo_Http.QuickRequestParams("GET","https://api.twilio.com/2010-04-01/Accounts/:AccountSid/Messages.json",loo_QueryParams)
if loo_Http.LastMethodSuccess = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_QueryParams
return
end if
loo_SbResponseBody = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")
loo_Resp.GetBodySb(loo_SbResponseBody)
loo_JResp = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")
loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0
Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()
li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
Write-Debug "Response Header:"
Write-Debug loo_Resp.Header
Write-Debug "Failed."
destroy loo_Resp
destroy loo_Http
destroy loo_QueryParams
destroy loo_SbResponseBody
destroy loo_JResp
return
end if
destroy loo_Resp
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "end": 51142961,
// "first_page_uri": "https://ZvltuXKxENEyvG.fnbzDIxrccIwHE6GxsyHjMd",
// "messages": [
// {
// "account_sid": "AC9E",
// "api_version": "commodo sint sunt eu",
// "body": "ut cillum",
// "date_created": "fugiat ipsum enim quis",
// "date_sent": "o",
// "date_updated": "laborum id esse elit",
// "direction": "outbound-reply",
// "error_code": 89665305,
// "error_message": "deserunt",
// "from": "anim esse",
// "messaging_service_sid": "MGC0",
// "num_media": "enim et",
// "num_segments": "quis qui ipsum",
// "price": "exercitation Duis",
// "price_unit": "consequat qu",
// "sid": "SMe5",
// "status": "scheduled",
// "subresource_uris": {},
// "to": "nulla",
// "uri": "cillum ut in irure"
// },
// {
// "account_sid": "ACD4",
// "api_version": "incididunt in non",
// "body": "deserunt incididunt irure eiusmod",
// "date_created": "sint ea",
// "date_sent": "Ut ut consectetur",
// "date_updated": "non dolore",
// "direction": "outbound-api",
// "error_code": -69524035,
// "error_message": "dolore Ut officia",
// "from": "reprehenderit",
// "messaging_service_sid": "MGEe",
// "num_media": "voluptate fugiat eiusmod qui Ut",
// "num_segments": "ea",
// "price": "consequat",
// "price_unit": "fugiat aliquip",
// "sid": "MM38",
// "status": "received",
// "subresource_uris": {},
// "to": "in tempor labore eiusmod",
// "uri": "elit non dol"
// }
// ],
// "next_page_uri": "http://fSikGpthYZQbOt.sncsPW4TzW44TkKnuDgx8f2FJz.",
// "page": -43897926,
// "page_size": 12121047,
// "previous_page_uri": "https://lSrGpSrECCMzKudcyRlwJdfhlnZEaAQ.hytgI,rCvOIy,x1C6vbgTvc9p6X2hkAdrqkd5jx8JKwJPiCrpsg2w",
// "start": -23084704,
// "uri": "https://USSzIQwA.hvxpmaT2476DlQGIi"
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
loo_Date_created = create oleobject
// Use "Chilkat_9_5_0.DtObj" for versions of Chilkat < 10.0.0
li_rc = loo_Date_created.ConnectToNewObject("Chilkat.DtObj")
loo_Date_sent = create oleobject
// Use "Chilkat_9_5_0.DtObj" for versions of Chilkat < 10.0.0
li_rc = loo_Date_sent.ConnectToNewObject("Chilkat.DtObj")
loo_Date_updated = create oleobject
// Use "Chilkat_9_5_0.DtObj" for versions of Chilkat < 10.0.0
li_rc = loo_Date_updated.ConnectToNewObject("Chilkat.DtObj")
li_V_end = loo_JResp.IntOf("end")
ls_First_page_uri = loo_JResp.StringOf("first_page_uri")
ls_Next_page_uri = loo_JResp.StringOf("next_page_uri")
li_Page = loo_JResp.IntOf("page")
li_Page_size = loo_JResp.IntOf("page_size")
ls_Previous_page_uri = loo_JResp.StringOf("previous_page_uri")
li_Start = loo_JResp.IntOf("start")
ls_Uri = loo_JResp.StringOf("uri")
i = 0
li_Count_i = loo_JResp.SizeOfArray("messages")
do while i < li_Count_i
loo_JResp.I = i
ls_Account_sid = loo_JResp.StringOf("messages[i].account_sid")
ls_Api_version = loo_JResp.StringOf("messages[i].api_version")
ls_Body = loo_JResp.StringOf("messages[i].body")
loo_JResp.DtOf("messages[i].date_created",0,loo_Date_created)
loo_JResp.DtOf("messages[i].date_sent",0,loo_Date_sent)
loo_JResp.DtOf("messages[i].date_updated",0,loo_Date_updated)
ls_Direction = loo_JResp.StringOf("messages[i].direction")
li_Error_code = loo_JResp.IntOf("messages[i].error_code")
ls_Error_message = loo_JResp.StringOf("messages[i].error_message")
ls_From = loo_JResp.StringOf("messages[i].from")
ls_Messaging_service_sid = loo_JResp.StringOf("messages[i].messaging_service_sid")
ls_Num_media = loo_JResp.StringOf("messages[i].num_media")
ls_Num_segments = loo_JResp.StringOf("messages[i].num_segments")
ls_Price = loo_JResp.StringOf("messages[i].price")
ls_Price_unit = loo_JResp.StringOf("messages[i].price_unit")
ls_Sid = loo_JResp.StringOf("messages[i].sid")
ls_Status = loo_JResp.StringOf("messages[i].status")
ls_V_to = loo_JResp.StringOf("messages[i].to")
ls_Uri = loo_JResp.StringOf("messages[i].uri")
i = i + 1
loop
destroy loo_Http
destroy loo_QueryParams
destroy loo_SbResponseBody
destroy loo_JResp
destroy loo_Date_created
destroy loo_Date_sent
destroy loo_Date_updated
Curl Command
curl -G -d "From=%7B%7BTWILIO_PHONE_NUMBER%7D%7D"
-u '{{TWILIO_ACCOUNT_SID}}:{{TWILIO_AUTH_TOKEN}}'
https://api.twilio.com/2010-04-01/Accounts/:AccountSid/Messages.json
Postman Collection Item JSON
{
"name": "List all messages sent from your Twilio number",
"event": [
{
"listen": "test",
"script": {
"exec": [
"var template = `",
" <table bgcolor=\"#FFFFFF\">",
" <tr>",
" <th>To</th>",
" <th>Message Body</th>",
" <th>Sent at</th>",
" </tr>",
"",
" {{#each messages}}",
" <tr>",
" <td>{{to}}</td>",
" <td>{{body}}</td>",
" <td>{{date_sent}}</td>",
" </tr>",
" {{/each}}",
" </table>",
"`;",
"",
"// Set visualizer",
"pm.visualizer.set(template, {",
" // Pass the response body parsed as JSON as `data`",
" messages: pm.response.json().messages",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "basic",
"basic": [
{
"key": "password",
"value": "{{TWILIO_AUTH_TOKEN}}",
"type": "string"
},
{
"key": "username",
"value": "{{TWILIO_ACCOUNT_SID}}",
"type": "string"
}
]
},
"method": "GET",
"header": [
],
"url": {
"raw": "{{2010-04-01-Accounts-AccountSid-Messages.json-Url}}/2010-04-01/Accounts/:AccountSid/Messages.json?From={{TWILIO_PHONE_NUMBER}}",
"host": [
"{{2010-04-01-Accounts-AccountSid-Messages.json-Url}}"
],
"path": [
"2010-04-01",
"Accounts",
":AccountSid",
"Messages.json"
],
"query": [
{
"key": "To",
"value": "<string>",
"description": "Read messages sent to only this phone number.",
"disabled": true
},
{
"key": "From",
"value": "{{TWILIO_PHONE_NUMBER}}",
"description": "Read messages sent from only this phone number or alphanumeric sender ID."
},
{
"key": "DateSent",
"value": "<dateTime>",
"description": "The date of the messages to show. Specify a date as `YYYY-MM-DD` in GMT to read only messages sent on this date. For example: `2009-07-06`. You can also specify an inequality, such as `DateSent<=YYYY-MM-DD`, to read messages sent on or before midnight on a date, and `DateSent>=YYYY-MM-DD` to read messages sent on or after midnight on a date.",
"disabled": true
},
{
"key": "DateSent<",
"value": "<dateTime>",
"description": "The date of the messages to show. Specify a date as `YYYY-MM-DD` in GMT to read only messages sent on this date. For example: `2009-07-06`. You can also specify an inequality, such as `DateSent<=YYYY-MM-DD`, to read messages sent on or before midnight on a date, and `DateSent>=YYYY-MM-DD` to read messages sent on or after midnight on a date.",
"disabled": true
},
{
"key": "DateSent>",
"value": "<dateTime>",
"description": "The date of the messages to show. Specify a date as `YYYY-MM-DD` in GMT to read only messages sent on this date. For example: `2009-07-06`. You can also specify an inequality, such as `DateSent<=YYYY-MM-DD`, to read messages sent on or before midnight on a date, and `DateSent>=YYYY-MM-DD` to read messages sent on or after midnight on a date.",
"disabled": true
},
{
"key": "PageSize",
"value": "<integer>",
"description": "How many resources to return in each list page. The default is 50, and the maximum is 1000.",
"disabled": true
}
],
"variable": [
{
"key": "AccountSid",
"value": "{{TWILIO_ACCOUNT_SID}}",
"description": "(Required) The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Message resources to read."
}
]
},
"description": "Retrieve a list of messages belonging to the account used to make the request. You can filter for example for only the messages that were sent from a specific phone number.\n\nRead more about it in the [Twilio Docs](https://www.twilio.com/docs/sms/api/message-resource#read-multiple-message-resources)"
},
"response": [
{
"name": "OK",
"originalRequest": {
"method": "GET",
"header": [
{
"description": "Added as a part of security scheme: basic",
"key": "Authorization",
"value": "Basic <credentials>"
}
],
"url": {
"raw": "{{2010-04-01-Accounts-AccountSid-Messages.json-Url}}/2010-04-01/Accounts/:AccountSid/Messages.json?To=<string>&From=<string>&DateSent=<dateTime>&DateSent<=<dateTime>&DateSent>=<dateTime>&PageSize=<integer>",
"host": [
"{{2010-04-01-Accounts-AccountSid-Messages.json-Url}}"
],
"path": [
"2010-04-01",
"Accounts",
":AccountSid",
"Messages.json"
],
"query": [
{
"key": "To",
"value": "<string>"
},
{
"key": "From",
"value": "<string>"
},
{
"key": "DateSent",
"value": "<dateTime>"
},
{
"key": "DateSent<",
"value": "<dateTime>"
},
{
"key": "DateSent>",
"value": "<dateTime>"
},
{
"key": "PageSize",
"value": "<integer>"
}
],
"variable": [
{
"key": "AccountSid"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"end\": 51142961,\n \"first_page_uri\": \"https://ZvltuXKxENEyvG.fnbzDIxrccIwHE6GxsyHjMd\",\n \"messages\": [\n {\n \"account_sid\": \"AC9E\",\n \"api_version\": \"commodo sint sunt eu\",\n \"body\": \"ut cillum\",\n \"date_created\": \"fugiat ipsum enim quis\",\n \"date_sent\": \"o\",\n \"date_updated\": \"laborum id esse elit\",\n \"direction\": \"outbound-reply\",\n \"error_code\": 89665305,\n \"error_message\": \"deserunt\",\n \"from\": \"anim esse\",\n \"messaging_service_sid\": \"MGC0\",\n \"num_media\": \"enim et\",\n \"num_segments\": \"quis qui ipsum\",\n \"price\": \"exercitation Duis\",\n \"price_unit\": \"consequat qu\",\n \"sid\": \"SMe5\",\n \"status\": \"scheduled\",\n \"subresource_uris\": {},\n \"to\": \"nulla\",\n \"uri\": \"cillum ut in irure\"\n },\n {\n \"account_sid\": \"ACD4\",\n \"api_version\": \"incididunt in non\",\n \"body\": \"deserunt incididunt irure eiusmod\",\n \"date_created\": \"sint ea\",\n \"date_sent\": \"Ut ut consectetur\",\n \"date_updated\": \"non dolore\",\n \"direction\": \"outbound-api\",\n \"error_code\": -69524035,\n \"error_message\": \"dolore Ut officia\",\n \"from\": \"reprehenderit\",\n \"messaging_service_sid\": \"MGEe\",\n \"num_media\": \"voluptate fugiat eiusmod qui Ut\",\n \"num_segments\": \"ea\",\n \"price\": \"consequat\",\n \"price_unit\": \"fugiat aliquip\",\n \"sid\": \"MM38\",\n \"status\": \"received\",\n \"subresource_uris\": {},\n \"to\": \"in tempor labore eiusmod\",\n \"uri\": \"elit non dol\"\n }\n ],\n \"next_page_uri\": \"http://fSikGpthYZQbOt.sncsPW4TzW44TkKnuDgx8f2FJz.\",\n \"page\": -43897926,\n \"page_size\": 12121047,\n \"previous_page_uri\": \"https://lSrGpSrECCMzKudcyRlwJdfhlnZEaAQ.hytgI,rCvOIy,x1C6vbgTvc9p6X2hkAdrqkd5jx8JKwJPiCrpsg2w\",\n \"start\": -23084704,\n \"uri\": \"https://USSzIQwA.hvxpmaT2476DlQGIi\"\n}"
}
]
}