Sample code for 30+ languages & platforms
PowerShell

WaTrend Create Instance

See more WaTrend Examples

Create a new WaTrend Instance ID.

Chilkat PowerShell Downloads

PowerShell
Add-Type -Path "C:\chilkat\ChilkatDotNet47-x64\ChilkatDotNet47.dll"

$success = $false

# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.

$http = New-Object Chilkat.Http

# Use your actual access token instead of 555555555555555555555555555555
$resp = New-Object Chilkat.HttpResponse
$success = $http.HttpNoBody("GET","https://app.watrend.com/api/createinstance.php?access_token=555555555555555555555555555555",$resp)
if ($success -eq $false) {
    $($http.LastErrorText)
    exit
}

$sbResponseBody = New-Object Chilkat.StringBuilder
$resp.GetBodySb($sbResponseBody)

$respStatusCode = $resp.StatusCode
$("Response Status Code = " + $respStatusCode)
if ($respStatusCode -ge 400) {
    $("Response Header:")
    $($resp.Header)
    $("Failed.")
    exit
}

# 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"}

$($resp.BodyStr)

$jResp = New-Object Chilkat.JsonObject
$jResp.LoadSb($sbResponseBody)

$status = $jResp.StringOf("status")
$instanceId = ""
if ($jResp.HasMember("instance_id") -eq $true) {
    $instanceId = $jResp.StringOf("instance_id")
}

$("status: " + $status)
$("instance_id: " + $instanceId)