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 Create InstanceSee more WaTrend ExamplesCreate a new WaTrend Instance ID.
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 ; Use your actual access token instead of 555555555555555555555555555555 resp.i = CkHttp::ckQuickRequest(http,"GET","https://app.watrend.com/api/createinstance.php?access_token=555555555555555555555555555555") If CkHttp::ckLastMethodSuccess(http) = 0 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) 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) CkStringBuilder::ckDispose(sbResponseBody) ProcedureReturn EndIf ; Both success and failed responses use 200 status code. ; A success response contains this JSON in the response body: ; {"status":"success","message":"Instance ID generated successfully","instance_id":"638EE5A76D3AA"} ; A failed response will contain something like this: ; {"status":"error","message":"Access token does not exist"} Debug CkHttpResponse::ckBodyStr(resp) 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") instanceId.s = "" If CkJsonObject::ckHasMember(jResp,"instance_id") = 1 instanceId = CkJsonObject::ckStringOf(jResp,"instance_id") EndIf Debug "status: " + status Debug "instance_id: " + instanceId CkHttpResponse::ckDispose(resp) CkHttp::ckDispose(http) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.