PowerBuilder Requires Chilkat v11.0.0+
PowerBuilder
Clickatell One API: Look up SMS delivery status
See more Clickatell Examples
Use the apiMessageId returned by the One API send example and the same integration key. The ID goes in the URL path. The SMS result contains sms.status and the timestamp of the last status change. For example, QUEUED means processing is pending and DEVICE_ACK indicates a device acknowledgment.
The response can also contain a WhatsApp result or have no identifiable channel for an unknown message. For ongoing delivery updates, configure delivery notifications in the integration. This example performs one lookup.
Chilkat PowerBuilder Downloads
integer li_rc
long li_Success
oleobject loo_Http
oleobject loo_Resp
oleobject loo_Reply
long li_Parsed
li_Success = 0
// Assumes Chilkat is unlocked. See Global Unlock Sample.
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
// Supply the key for this One API integration from application configuration.
loo_Http.SetRequestHeader("Authorization","ONE_API_KEY")
loo_Http.SetRequestHeader("Accept","application/json")
// Use the provider-generated ID from an accepted One API send.
loo_Http.SetUrlVar("id","ONE_API_MESSAGE_ID")
loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")
li_Success = loo_Http.HttpNoBody("GET","https://platform.clickatell.com/v1/message/{$id}",loo_Resp)
if loo_Resp.StatusCode = 0 then
Write-Debug "No HTTP response. Check the connection and retry the lookup."
destroy loo_Http
destroy loo_Resp
return
end if
loo_Reply = create oleobject
li_rc = loo_Reply.ConnectToNewObject("Chilkat.JsonObject")
li_Parsed = loo_Reply.Load(loo_Resp.BodyStr)
if (li_Success <> 1) OR ((loo_Resp.StatusCode <> 200)) then
Write-Debug "Clickatell returned HTTP " + string(loo_Resp.StatusCode)
if li_Parsed = 1 then
if loo_Reply.HasMember("error.description") = 1 then
Write-Debug loo_Reply.StringOf("error.description")
end if
end if
destroy loo_Http
destroy loo_Resp
destroy loo_Reply
return
end if
if li_Parsed <> 1 then
Write-Debug "Expected a JSON response."
destroy loo_Http
destroy loo_Resp
destroy loo_Reply
return
end if
// A known SMS has a string status under the sms member.
if loo_Reply.JsonTypeOf("sms.status") <> 1 then
if loo_Reply.JsonTypeOf("whatsapp.status") = 1 then
Write-Debug "This message has WhatsApp status: " + loo_Reply.StringOf("whatsapp.status")
else
Write-Debug "No SMS status was returned. Check the message ID and integration."
if loo_Reply.JsonTypeOf("status") = 1 then
Write-Debug "Reported status: " + loo_Reply.StringOf("status")
end if
end if
destroy loo_Http
destroy loo_Resp
destroy loo_Reply
return
end if
Write-Debug "SMS status: " + loo_Reply.StringOf("sms.status")
if loo_Reply.JsonTypeOf("sms.timestamp") = 2 then
// Read the provider timestamp as text to preserve every digit.
Write-Debug "Last status change (provider timestamp): " + loo_Reply.StringOf("sms.timestamp")
end if
destroy loo_Http
destroy loo_Resp
destroy loo_Reply