PowerBuilder Requires Chilkat v11.0.0+
PowerBuilder
Clickatell One API: Send an approved WhatsApp shipment template
See more Clickatell Examples
Send a business-initiated shipment update, including outside an open customer service window. First approve a template on the WhatsApp integration with two positional body placeholders for the order number and delivery date. Supply its exact name and approved language. The keys 1 and 2 refer to those placeholders in order.
Chilkat PowerBuilder Downloads
integer li_rc
oleobject loo_Http
oleobject loo_Body
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")
// Example approved wording: Order {{1}} is due for delivery on {{2}}.
loo_Body = create oleobject
li_rc = loo_Body.ConnectToNewObject("Chilkat.JsonObject")
loo_Body.UpdateString("messages[0].channel","whatsapp")
loo_Body.UpdateString("messages[0].to","PHONE_NUMBER")
loo_Body.UpdateString("messages[0].template.templateName","shipment_update")
loo_Body.UpdateString("messages[0].template.language","en_US")
loo_Body.UpdateString("messages[0].template.body.parameters.1","ORD-1042")
loo_Body.UpdateString("messages[0].template.body.parameters.2","March 19")
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) 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
// 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_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_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_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_Body
destroy loo_Resp
destroy loo_Reply