PowerBuilder Requires Chilkat v11.0.0+
PowerBuilder
Clickatell One API: Send personalized SMS reminders in a batch
See more Clickatell Examples
Send two appointments in one request with a different text and application ID for each. Use two distinct recipient numbers in international digits. For a US two-way integration, add its provisioned from number to each message.
Read each recipient result even when HTTP 207 reports a mixed outcome. Save the accepted provider ID against the appointment. A missing result calls for checking the message report before retrying. A client message ID helps correlate records and does not guarantee deduplication.
Chilkat PowerBuilder Downloads
integer li_rc
oleobject loo_Http
string ls_FirstPhone
string ls_SecondPhone
oleobject loo_Body
oleobject loo_Resp
long li_Sent
oleobject loo_Reply
long li_Parsed
oleobject loo_Results
long i
string ls_Appointment
string ls_Phone
oleobject loo_Result
long li_Found
long li_Saved
// 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")
ls_FirstPhone = "FIRST_PHONE_NUMBER"
ls_SecondPhone = "SECOND_PHONE_NUMBER"
loo_Body = create oleobject
li_rc = loo_Body.ConnectToNewObject("Chilkat.JsonObject")
loo_Body.UpdateString("messages[0].channel","sms")
loo_Body.UpdateString("messages[0].to",ls_FirstPhone)
loo_Body.UpdateString("messages[0].content","Your appointment with Lee is at 10:00.")
loo_Body.UpdateString("messages[0].clientMessageId","appt-1042")
loo_Body.UpdateString("messages[1].channel","sms")
loo_Body.UpdateString("messages[1].to",ls_SecondPhone)
loo_Body.UpdateString("messages[1].content","Your appointment with Sam is at 14:30.")
loo_Body.UpdateString("messages[1].clientMessageId","appt-1043")
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_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) AND (loo_Resp.StatusCode <> 207)) 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_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_Body
destroy loo_Resp
destroy loo_Reply
return
end if
end if
// Look up each submitted appointment in the reply using its unique recipient.
// This works even if the result order changes or clientMessageId is absent.
loo_Results = create oleobject
li_rc = loo_Results.ConnectToNewObject("Chilkat.JsonObject")
i = 0
do while (i < 2)
loo_Body.I = i
ls_Appointment = loo_Body.StringOf("messages[i].clientMessageId")
ls_Phone = loo_Body.StringOf("messages[i].to")
loo_Result = create oleobject
li_rc = loo_Result.ConnectToNewObject("Chilkat.JsonObject")
li_Found = loo_Reply.FindRecord2("messages","to",ls_Phone,1,loo_Result)
loo_Results.I = i
loo_Results.UpdateString("appointments[i].clientMessageId",ls_Appointment)
if (li_Found <> 1) OR (loo_Result.JsonTypeOf("accepted") <> 5) then
loo_Results.UpdateString("appointments[i].outcome","unknown")
Write-Debug ls_Appointment + " has no confirmed result."
else
if loo_Result.BoolOf("accepted") = 1 then
loo_Results.UpdateString("appointments[i].outcome","accepted")
if loo_Result.JsonTypeOf("apiMessageId") = 1 then
loo_Results.UpdateString("appointments[i].apiMessageId",loo_Result.StringOf("apiMessageId"))
end if
Write-Debug ls_Appointment + " accepted."
else
loo_Results.UpdateString("appointments[i].outcome","rejected")
loo_Results.UpdateString("appointments[i].reason",loo_Result.StringOf("error.description"))
Write-Debug ls_Appointment + " rejected: " + loo_Result.StringOf("error.description")
end if
end if
i = i + 1
loop
// This demo writes a snapshot. In an application, update the two appointment records.
li_Saved = loo_Results.WriteFile("appointment-send-results.json")
if li_Saved <> 1 then
Write-Debug "Could not save the results. Reconcile the submitted messages before retrying."
destroy loo_Http
destroy loo_Body
destroy loo_Resp
destroy loo_Reply
destroy loo_Results
destroy loo_Result
return
end if
Write-Debug "Saved appointment-send-results.json"
destroy loo_Http
destroy loo_Body
destroy loo_Resp
destroy loo_Reply
destroy loo_Results
destroy loo_Result