PowerBuilder Requires Chilkat v11.0.0+
PowerBuilder
Clickatell One API: Schedule a time-limited SMS reminder
See more Clickatell Examples
Schedule a reminder 15 minutes from now in UTC. The scheduledDeliveryTime includes its time zone and validityPeriod is expressed in minutes. Set both from the appointment and the period for which the reminder will still be useful. Use the returned message ID for a later status lookup.
Supply an international number as digits. Set the sender to the provisioned number when the integration requires it.
Chilkat PowerBuilder Downloads
integer li_rc
oleobject loo_Http
oleobject loo_Schedule
string ls_SendAt
oleobject loo_Body
string ls_Sender
oleobject loo_Resp
long li_Sent
oleobject loo_Reply
long li_Parsed
// 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
// Load the key for this One API integration from your application configuration.
loo_Http.SetRequestHeader("Authorization","ONE_API_KEY")
loo_Http.SetRequestHeader("Accept","application/json")
loo_Schedule = create oleobject
li_rc = loo_Schedule.ConnectToNewObject("Chilkat.CkDateTime")
loo_Schedule.SetFromCurrentSystemTime()
loo_Schedule.AddSeconds(900)
ls_SendAt = loo_Schedule.GetAsTimestamp(0)
loo_Body = create oleobject
li_rc = loo_Body.ConnectToNewObject("Chilkat.JsonObject")
loo_Body.UpdateString("messages[0].channel","sms")
loo_Body.UpdateString("messages[0].to","PHONE_NUMBER")
loo_Body.UpdateString("messages[0].content","Appointment reminder: please check in at reception.")
loo_Body.UpdateString("messages[0].scheduledDeliveryTime",ls_SendAt)
loo_Body.UpdateInt("messages[0].validityPeriod",60)
ls_Sender = ""
if ls_Sender <> "" then
loo_Body.UpdateString("messages[0].from",ls_Sender)
end if
Write-Debug "Requested send time (UTC): " + ls_SendAt
loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")
li_Sent = loo_Http.HttpJson("POST","https://platform.clickatell.com/v1/message",loo_Body,"application/json",loo_Resp)
if loo_Resp.StatusCode = 0 then
Write-Debug "No HTTP response. Check the message report before resending."
destroy loo_Http
destroy loo_Schedule
destroy loo_Body
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_Sent <> 1) OR (loo_Resp.StatusCode <> 202) then
Write-Debug "Send returned HTTP " + string(loo_Resp.StatusCode)
if loo_Reply.HasMember("error.description") = 1 then
Write-Debug loo_Reply.StringOf("error.description")
end if
destroy loo_Http
destroy loo_Schedule
destroy loo_Body
destroy loo_Resp
destroy loo_Reply
return
end if
if loo_Reply.HasMember("error.code") = 1 then
if loo_Reply.IsNullOf("error.code") <> 1 then
Write-Debug "Submission error " + loo_Reply.StringOf("error.code") + " " + loo_Reply.StringOf("error.description")
destroy loo_Http
destroy loo_Schedule
destroy loo_Body
destroy loo_Resp
destroy loo_Reply
return
end if
end if
// HTTP acceptance and the recipient result are separate checks.
if (li_Parsed <> 1) OR (loo_Reply.JsonTypeOf("messages[0].accepted") <> 5) then
Write-Debug "Missing recipient result. Check the message report."
destroy loo_Http
destroy loo_Schedule
destroy loo_Body
destroy loo_Resp
destroy loo_Reply
return
end if
if loo_Reply.BoolOf("messages[0].accepted") <> 1 then
Write-Debug "Message rejected: " + loo_Reply.StringOf("messages[0].error.code") + " " + loo_Reply.StringOf("messages[0].error.description")
destroy loo_Http
destroy loo_Schedule
destroy loo_Body
destroy loo_Resp
destroy loo_Reply
return
end if
if loo_Reply.JsonTypeOf("messages[0].apiMessageId") <> 1 then
Write-Debug "Accepted without a message ID. Check the message report."
destroy loo_Http
destroy loo_Schedule
destroy loo_Body
destroy loo_Resp
destroy loo_Reply
return
end if
Write-Debug "Accepted. Message ID: " + loo_Reply.StringOf("messages[0].apiMessageId")
destroy loo_Http
destroy loo_Schedule
destroy loo_Body
destroy loo_Resp
destroy loo_Reply