Java
Chilkat2 Java
WaTrend Create Instance
See more WaTrend Examples
Create a new WaTrend Instance ID.Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.HttpResponse;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.StringBuilder;
public class ChilkatExample {
public static void main(String[] args) {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Http http = new Http();
// Use your actual access token instead of 555555555555555555555555555555
HttpResponse resp = new HttpResponse();
try {
http.httpNoBody("GET", "https://app.watrend.com/api/createinstance.php?access_token=555555555555555555555555555555", resp);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
StringBuilder sbResponseBody = new StringBuilder();
resp.getBodySb(sbResponseBody);
int respStatusCode = resp.getStatusCode();
System.out.println("Response Status Code = " + respStatusCode);
if (respStatusCode >= 400) {
System.out.println("Response Header:");
System.out.println(resp.getHeader());
System.out.println("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"}
System.out.println(resp.getBodyStr());
JsonObject jResp = new JsonObject();
jResp.loadSb(sbResponseBody);
String status = jResp.stringOf("status");
String instanceId = "";
if (jResp.hasMember("instance_id")) {
instanceId = jResp.stringOf("instance_id");
}
System.out.println("status: " + status);
System.out.println("instance_id: " + instanceId);
}
}