Sample code for 30+ languages & platforms
PHP

WaTrend Create Instance

See more WaTrend Examples

Create a new WaTrend Instance ID.

Chilkat PHP Downloads

PHP
<?php

use Chilkat2\Http;
use Chilkat2\HttpResponse;
use Chilkat2\JsonObject;
use Chilkat2\StringBuilder;

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

$http = new Http();

// Use your actual access token instead of 555555555555555555555555555555
$resp = new HttpResponse();
try {
    $http->HttpNoBody('GET', 'https://app.watrend.com/api/createinstance.php?access_token=555555555555555555555555555555', $resp);
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

$sbResponseBody = new StringBuilder();
$resp->GetBodySb($sbResponseBody);

$respStatusCode = $resp->StatusCode;
echo 'Response Status Code = ', $respStatusCode, "\n";
if ($respStatusCode >= 400) {
    echo "Response Header:\n";
    echo $resp->Header, "\n";
    echo "Failed.\n";
    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"}

echo $resp->BodyStr, "\n";

$jResp = new JsonObject();
$jResp->LoadSb($sbResponseBody);

$status = $jResp->StringOf('status');
$instanceId = '';
if ($jResp->HasMember('instance_id')) {
    $instanceId = $jResp->StringOf('instance_id');
}

echo 'status: ', $status, "\n";
echo 'instance_id: ', $instanceId, "\n";