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) WaTrend Send WhatsApp TextSee more WaTrend ExamplesSend a WhatsApp text.
IncludeFile "CkHttpResponse.pb" IncludeFile "CkHttp.pb" IncludeFile "CkStringBuilder.pb" IncludeFile "CkJsonObject.pb" IncludeFile "CkHttpRequest.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 ; Use your actual access token instead of 555555555555555555555555555555 req.i = CkHttpRequest::ckCreate() If req.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkHttpRequest::ckAddParam(req,"number","84933313xxx") CkHttpRequest::ckAddParam(req,"type","text") CkHttpRequest::ckAddParam(req,"message","This is a test message") CkHttpRequest::ckAddParam(req,"instance_id","609ACF283XXXX") CkHttpRequest::ckAddParam(req,"access_token","555555555555555555555555555555") ; Note: The WaTrend online documentation indicate a POST should be used. ; However, it seems you might actually need to send a GET request. ; It is unclear. ; If a GET is neeed, you would just send to the URL w/ query params like this: sbUrl.i = CkStringBuilder::ckCreate() If sbUrl.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkStringBuilder::ckAppend(sbUrl,"https://app.watrend.com/api/send.php?") CkStringBuilder::ckAppend(sbUrl,CkHttpRequest::ckGetUrlEncodedParams(req)) responseBodyStr.s = CkHttp::ckQuickGetStr(http,CkStringBuilder::ckGetAsString(sbUrl)) ; The responseBodyStr contains the JSON response from the server.. ; If a POST is needed, then it is sent like this: resp.i = CkHttp::ckPostUrlEncoded(http,"https://app.watrend.com/api/send.php",req) If CkHttp::ckLastMethodSuccess(http) = 0 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) CkHttpRequest::ckDispose(req) CkStringBuilder::ckDispose(sbUrl) ProcedureReturn EndIf sbResponseBody.i = CkStringBuilder::ckCreate() If sbResponseBody.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkHttpResponse::ckGetBodySb(resp,sbResponseBody) 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) CkHttpRequest::ckDispose(req) CkStringBuilder::ckDispose(sbUrl) CkStringBuilder::ckDispose(sbResponseBody) ProcedureReturn EndIf Debug CkHttpResponse::ckBodyStr(resp) ; Both success and failed responses use 200 status code. ; A success response contains this JSON in the response body: ; {"status":"success", ... } ; A failed response will contain something like this: ; {"status":"error","message":"License Invalidated"} jResp.i = CkJsonObject::ckCreate() If jResp.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckLoadSb(jResp,sbResponseBody) status.s = CkJsonObject::ckStringOf(jResp,"status") Debug "status: " + status CkHttpResponse::ckDispose(resp) CkHttp::ckDispose(http) CkHttpRequest::ckDispose(req) CkStringBuilder::ckDispose(sbUrl) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.