Sample code for 30+ languages & platforms
PowerBuilder Requires Chilkat v11.0.0+

Check message delivery status with Twilio

See more Twilio Examples

Fetch an outbound SMS or MMS using the Message SID returned by a live send. A queued message is waiting to be sent. A sent message has been accepted by the upstream carrier. Delivered means Twilio received delivery confirmation. Some routes provide no final delivery receipt.

Read the current status once per lookup. For failed or undelivered messages, display the available delivery error code and text for troubleshooting. A missing message or an HTTP authentication error is a separate result from a delivery failure.

Twilio documentation

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
oleobject loo_Http
oleobject loo_Url
oleobject loo_Resp
oleobject loo_Reply
long li_Parsed

li_Success = 0

//  Assumes Chilkat is unlocked. See Global Unlock Sample.
//  Load an API key for the Twilio account from private application configuration.
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
loo_Http.RequireSslCertVerify = 1
loo_Http.BasicAuth = 1
loo_Http.Login = "YOUR_API_KEY_SID"
loo_Http.Password = "YOUR_API_KEY_SECRET"

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

loo_Url.Append("https://api.twilio.com/2010-04-01/Accounts/")
loo_Url.Append("YOUR_ACCOUNT_SID")
loo_Url.Append("/Messages")
loo_Url.Append("/")
loo_Url.Append("YOUR_MESSAGE_SID")
loo_Url.Append(".json")
loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")

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

li_Success = loo_Http.HttpNoBody("GET",loo_Url.GetAsString(),loo_Resp)
if loo_Resp.StatusCode = 0 then
    Write-Debug "No HTTP response from Twilio."
    destroy loo_Http
    destroy loo_Url
    destroy loo_Resp
    destroy loo_Reply
    return
end if

li_Parsed = loo_Reply.Load(loo_Resp.BodyStr)
if (li_Success <> 1) OR (loo_Resp.StatusCode <> 200) then
    Write-Debug "Twilio returned HTTP " + string(loo_Resp.StatusCode)
    if (li_Parsed = 1) AND (loo_Reply.JsonTypeOf("code") = 2) then
        Write-Debug "Twilio error: " + string(loo_Reply.IntOf("code")) + "  " + loo_Reply.StringOf("message")
    end if

    destroy loo_Http
    destroy loo_Url
    destroy loo_Resp
    destroy loo_Reply
    return
end if

if li_Parsed <> 1 then
    Write-Debug "Expected a JSON response from Twilio."
    destroy loo_Http
    destroy loo_Url
    destroy loo_Resp
    destroy loo_Reply
    return
end if

if loo_Reply.JsonTypeOf("status") <> 1 then
    Write-Debug "Message status missing from response."
    destroy loo_Http
    destroy loo_Url
    destroy loo_Resp
    destroy loo_Reply
    return
end if

Write-Debug "Delivery status: " + loo_Reply.StringOf("status")
if (loo_Reply.StringOfEquals("status","failed",1) = 1) OR (loo_Reply.StringOfEquals("status","undelivered",1) = 1) then
    if loo_Reply.JsonTypeOf("error_code") = 2 then
        Write-Debug "Delivery error code: " + string(loo_Reply.IntOf("error_code"))
    end if

    if loo_Reply.JsonTypeOf("error_message") = 1 then
        Write-Debug loo_Reply.StringOf("error_message")
    end if

end if



destroy loo_Http
destroy loo_Url
destroy loo_Resp
destroy loo_Reply