Sample code for 30+ languages & platforms
Node.js

WaTrend Create Instance

See more WaTrend Examples

Create a new WaTrend Instance ID.

Chilkat Node.js Downloads

Node.js
NODEJS_PRELUDE

function chilkatExample() {

    var success = false;

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

    var http = new chilkat.Http();

    // Use your actual access token instead of 555555555555555555555555555555
    var resp = new chilkat.HttpResponse();
    success = http.HttpNoBody("GET","https://app.watrend.com/api/createinstance.php?access_token=555555555555555555555555555555",resp);
    if (success == false) {
        console.log(http.LastErrorText);
        return;
    }

    var sbResponseBody = new chilkat.StringBuilder();
    resp.GetBodySb(sbResponseBody);

    var respStatusCode = resp.StatusCode;
    console.log("Response Status Code = " + respStatusCode);
    if (respStatusCode >= 400) {
        console.log("Response Header:");
        console.log(resp.Header);
        console.log("Failed.");
        return;
    }

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

    console.log(resp.BodyStr);

    var jResp = new chilkat.JsonObject();
    jResp.LoadSb(sbResponseBody);

    var status = jResp.StringOf("status");
    var instanceId = "";
    if (jResp.HasMember("instance_id") == true) {
        instanceId = jResp.StringOf("instance_id");
    }

    console.log("status: " + status);
    console.log("instance_id: " + instanceId);

}

chilkatExample();