Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) Clickatell Send SMS Text MessageSee more Clickatell ExamplesDemonstrate how to send a Clickatell SMS text message. For more information, see https://docs.clickatell.com/channels/sms-channels/sms-api-reference/
IncludeFile "CkHttpResponse.pb" IncludeFile "CkHttp.pb" IncludeFile "CkStringBuilder.pb" IncludeFile "CkJsonObject.pb" Procedure ChilkatExample() ; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i ; Implements the following CURL command: ; curl -i \ ; -X POST \ ; -H "Content-Type: application/json" \ ; -H "Accept: application/json" \ ; -H "Authorization: API_KEY" \ ; -d '{"content": "Test Message Text", "to": ["PHONE_NUMBER"], "from": "FROM_PHONE_NUMBER" }' \ ; -s https://platform.clickatell.com/messages ; Use this online tool to generate code from sample JSON: ; Generate Code to Create JSON ; The following JSON is sent in the request body. ; { ; "content": "Test Message Text", ; "to": [ ; "PHONE_NUMBER" ; ] ; } json.i = CkJsonObject::ckCreate() If json.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckUpdateString(json,"content","Test Message Text") CkJsonObject::ckUpdateString(json,"to[0]","PHONE_NUMBER") CkJsonObject::ckUpdateString(json,"from","FROM_PHONE_NUMBER") CkHttp::ckSetRequestHeader(http,"Authorization","API_KEY") CkHttp::ckSetRequestHeader(http,"Accept","application/json") CkHttp::ckSetRequestHeader(http,"Content-Type","application/json") ; If the following URL does not work, then try "https://platform.clickatell.com/v1/message" resp.i = CkHttp::ckPostJson3(http,"https://platform.clickatell.com/messages","application/json",json) If CkHttp::ckLastMethodSuccess(http) = 0 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) CkJsonObject::ckDispose(json) ProcedureReturn EndIf sbResponseBody.i = CkStringBuilder::ckCreate() If sbResponseBody.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkHttpResponse::ckGetBodySb(resp,sbResponseBody) jResp.i = CkJsonObject::ckCreate() If jResp.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckLoadSb(jResp,sbResponseBody) CkJsonObject::setCkEmitCompact(jResp, 0) Debug "Response Body:" Debug CkJsonObject::ckEmit(jResp) respStatusCode.i = CkHttpResponse::ckStatusCode(resp) Debug "Response Status Code = " + Str(respStatusCode) If respStatusCode >= 400 Debug "Response Header:" Debug CkHttpResponse::ckHeader(resp) Debug "Failed." CkHttpResponse::ckDispose(resp) CkHttp::ckDispose(http) CkJsonObject::ckDispose(json) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndIf CkHttpResponse::ckDispose(resp) ; Sample JSON response: ; (Sample code for parsing the JSON response is shown below) ; { ; "messages": [ ; { ; "apiMessageId": "66c06ac68e5c4afb953ea9328babfde6", ; "accepted": true, ; "to": "16302581871", ; "errorCode": null, ; "error": null, ; "errorDescription": null ; } ; ], ; "errorCode": null, ; "error": null, ; "errorDescription": null ; } ; Sample code for parsing the JSON response... ; Use the following online tool to generate parsing code from sample JSON: ; Generate Parsing Code from JSON errorCode.s error.s errorDescription.s i.i count_i.i apiMessageId.s accepted.i v_to.s errorCode = CkJsonObject::ckStringOf(jResp,"errorCode") error = CkJsonObject::ckStringOf(jResp,"error") errorDescription = CkJsonObject::ckStringOf(jResp,"errorDescription") i = 0 count_i = CkJsonObject::ckSizeOfArray(jResp,"messages") While i < count_i CkJsonObject::setCkI(jResp, i) apiMessageId = CkJsonObject::ckStringOf(jResp,"messages[i].apiMessageId") accepted = CkJsonObject::ckBoolOf(jResp,"messages[i].accepted") v_to = CkJsonObject::ckStringOf(jResp,"messages[i].to") errorCode = CkJsonObject::ckStringOf(jResp,"messages[i].errorCode") error = CkJsonObject::ckStringOf(jResp,"messages[i].error") errorDescription = CkJsonObject::ckStringOf(jResp,"messages[i].errorDescription") i = i + 1 Wend CkHttp::ckDispose(http) CkJsonObject::ckDispose(json) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.