DataFlex
DataFlex
WaTrend Create Instance
See more WaTrend Examples
Create a new WaTrend Instance ID.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoHttp
Variant vResp
Handle hoResp
Variant vSbResponseBody
Handle hoSbResponseBody
Integer iRespStatusCode
Handle hoJResp
String sStatus
String sInstanceId
String sTemp1
Boolean bTemp1
Move False To iSuccess
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
// Use your actual access token instead of 555555555555555555555555555555
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://app.watrend.com/api/createinstance.php?access_token=555555555555555555555555555555" vResp To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
Send CreateComObject of hoSbResponseBody
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess
Get ComStatusCode Of hoResp To iRespStatusCode
Showln "Response Status Code = " iRespStatusCode
If (iRespStatusCode >= 400) Begin
Showln "Response Header:"
Get ComHeader Of hoResp To sTemp1
Showln sTemp1
Showln "Failed."
Procedure_Return
End
// 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"}
Get ComBodyStr Of hoResp To sTemp1
Showln sTemp1
Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
If (Not(IsComObjectCreated(hoJResp))) Begin
Send CreateComObject of hoJResp
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
Get ComStringOf Of hoJResp "status" To sStatus
Move "" To sInstanceId
Get ComHasMember Of hoJResp "instance_id" To bTemp1
If (bTemp1 = True) Begin
Get ComStringOf Of hoJResp "instance_id" To sInstanceId
End
Showln "status: " sStatus
Showln "instance_id: " sInstanceId
End_Procedure