DataFlex Requires Chilkat v11.0.0+
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoHttp
Variant vResp
Handle hoResp
Handle hoReply
Boolean iParsed
String sTemp1
Integer iTemp1
Boolean bTemp1
Move False To iSuccess
// Assumes Chilkat is unlocked. See Global Unlock Sample.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
Set ComRequireSslCertVerify Of hoHttp To True
// Supply the key for this One API integration from application configuration.
Send ComSetRequestHeader To hoHttp "Authorization" "ONE_API_KEY"
Send ComSetRequestHeader To hoHttp "Accept" "application/json"
// Use the provider-generated ID from an accepted One API send.
Get ComSetUrlVar Of hoHttp "id" "ONE_API_MESSAGE_ID" To iSuccess
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
If (Not(IsComObjectCreated(hoResp))) Begin
Send CreateComObject of hoResp
End
Get pvComObject of hoResp to vResp
Get ComHttpNoBody Of hoHttp "GET" "https://platform.clickatell.com/v1/message/{$id}" vResp To iSuccess
Get ComStatusCode Of hoResp To iTemp1
If (iTemp1 = 0) Begin
Showln "No HTTP response. Check the connection and retry the lookup."
Procedure_Return
End
Get Create (RefClass(cComChilkatJsonObject)) To hoReply
If (Not(IsComObjectCreated(hoReply))) Begin
Send CreateComObject of hoReply
End
Get ComBodyStr Of hoResp To sTemp1
Get ComLoad Of hoReply sTemp1 To iParsed
Get ComStatusCode Of hoResp To iTemp1
If ((iSuccess <> True) Or ((iTemp1 <> 200))) Begin
Get ComStatusCode Of hoResp To iTemp1
Showln "Clickatell returned HTTP " iTemp1
If (iParsed = True) Begin
Get ComHasMember Of hoReply "error.description" To bTemp1
If (bTemp1 = True) Begin
Get ComStringOf Of hoReply "error.description" To sTemp1
Showln sTemp1
End
End
Procedure_Return
End
If (iParsed <> True) Begin
Showln "Expected a JSON response."
Procedure_Return
End
// A known SMS has a string status under the sms member.
Get ComJsonTypeOf Of hoReply "sms.status" To iTemp1
If (iTemp1 <> 1) Begin
Get ComJsonTypeOf Of hoReply "whatsapp.status" To iTemp1
If (iTemp1 = 1) Begin
Get ComStringOf Of hoReply "whatsapp.status" To sTemp1
Showln "This message has WhatsApp status: " sTemp1
End
Else Begin
Showln "No SMS status was returned. Check the message ID and integration."
Get ComJsonTypeOf Of hoReply "status" To iTemp1
If (iTemp1 = 1) Begin
Get ComStringOf Of hoReply "status" To sTemp1
Showln "Reported status: " sTemp1
End
End
Procedure_Return
End
Get ComStringOf Of hoReply "sms.status" To sTemp1
Showln "SMS status: " sTemp1
Get ComJsonTypeOf Of hoReply "sms.timestamp" To iTemp1
If (iTemp1 = 2) Begin
// Read the provider timestamp as text to preserve every digit.
Get ComStringOf Of hoReply "sms.timestamp" To sTemp1
Showln "Last status change (provider timestamp): " sTemp1
End
End_Procedure