Rust
Rust
WaTrend Create Instance
See more WaTrend Examples
Create a new WaTrend Instance ID.Chilkat Rust Downloads
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = chilkat::Http::new();
// Use your actual access token instead of 555555555555555555555555555555
let resp = chilkat::HttpResponse::new();
if http.http_no_body("GET", "https://app.watrend.com/api/createinstance.php?access_token=555555555555555555555555555555", &resp).is_err() {
println!("{}", http.last_error_text());
return;
}
let sb_response_body = chilkat::StringBuilder::new();
let _ = resp.get_body_sb(&sb_response_body);
let resp_status_code = resp.status_code();
println!("Response Status Code = {}", resp_status_code);
if resp_status_code >= 400 {
println!("Response Header:");
println!("{}", resp.header());
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"}
println!("{}", resp.body_str());
let j_resp = chilkat::JsonObject::new();
let _ = j_resp.load_sb(&sb_response_body);
let status = j_resp.string_of("status").unwrap_or_default();
let mut instance_id = String::new();
if j_resp.has_member("instance_id") {
instance_id = j_resp.string_of("instance_id").unwrap_or_default();
}
println!("status: {}", status);
println!("instance_id: {}", instance_id);