Visual FoxPro Requires Chilkat v11.0.0+
Visual FoxPro
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 Visual FoxPro Downloads
LOCAL loHttp
LOCAL loBody
LOCAL loResp
LOCAL lnSent
LOCAL loReply
LOCAL lnParsed
* Assumes Chilkat is unlocked. See Global Unlock Sample.
loHttp = CreateObject('Chilkat.Http')
loHttp.RequireSslCertVerify = 1
* Load the key for this One API integration from your application configuration.
loHttp.SetRequestHeader("Authorization","ONE_API_KEY")
loHttp.SetRequestHeader("Accept","application/json")
* Example approved wording: Order {{1}} is due for delivery on {{2}}.
loBody = CreateObject('Chilkat.JsonObject')
loBody.UpdateString("messages[0].channel","whatsapp")
loBody.UpdateString("messages[0].to","PHONE_NUMBER")
loBody.UpdateString("messages[0].template.templateName","shipment_update")
loBody.UpdateString("messages[0].template.language","en_US")
loBody.UpdateString("messages[0].template.body.parameters.1","ORD-1042")
loBody.UpdateString("messages[0].template.body.parameters.2","March 19")
loResp = CreateObject('Chilkat.HttpResponse')
lnSent = loHttp.HttpJson("POST","https://platform.clickatell.com/v1/message",loBody,"application/json",loResp)
IF (loResp.StatusCode = 0) THEN
? "No HTTP response. Check the message report before resending."
RELEASE loHttp
RELEASE loBody
RELEASE loResp
CANCEL
ENDIF
loReply = CreateObject('Chilkat.JsonObject')
lnParsed = loReply.Load(loResp.BodyStr)
IF ((lnSent <> 1) OR (loResp.StatusCode <> 202)) THEN
? "Send returned HTTP " + STR(loResp.StatusCode)
IF (loReply.HasMember("error.description") = 1) THEN
? loReply.StringOf("error.description")
ENDIF
RELEASE loHttp
RELEASE loBody
RELEASE loResp
RELEASE loReply
CANCEL
ENDIF
IF (loReply.HasMember("error.code") = 1) THEN
IF (loReply.IsNullOf("error.code") <> 1) THEN
? "Submission error " + loReply.StringOf("error.code") + " " + loReply.StringOf("error.description")
RELEASE loHttp
RELEASE loBody
RELEASE loResp
RELEASE loReply
CANCEL
ENDIF
ENDIF
* HTTP acceptance and the recipient result are separate checks.
IF ((lnParsed <> 1) OR (loReply.JsonTypeOf("messages[0].accepted") <> 5)) THEN
? "Missing recipient result. Check the message report."
RELEASE loHttp
RELEASE loBody
RELEASE loResp
RELEASE loReply
CANCEL
ENDIF
IF (loReply.BoolOf("messages[0].accepted") <> 1) THEN
? "Message rejected: " + loReply.StringOf("messages[0].error.code") + " " + loReply.StringOf("messages[0].error.description")
RELEASE loHttp
RELEASE loBody
RELEASE loResp
RELEASE loReply
CANCEL
ENDIF
IF (loReply.JsonTypeOf("messages[0].apiMessageId") <> 1) THEN
? "Accepted without a message ID. Check the message report."
RELEASE loHttp
RELEASE loBody
RELEASE loResp
RELEASE loReply
CANCEL
ENDIF
? "Accepted. Message ID: " + loReply.StringOf("messages[0].apiMessageId")
RELEASE loHttp
RELEASE loBody
RELEASE loResp
RELEASE loReply