Sample code for 30+ languages & platforms
Rust

Adobe Analytics Reporting API (1.4)

See more HTTP Misc Examples

Demonstrates a simple POST of JSON to the Adobe Analytics Reporting API (v1.4)

Chilkat Rust Downloads

Rust

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

// In this example, replace "rsid" with your report suite id, and update the URL to use the correct endpoint
let url = "https://api.omniture.com/admin/1.4/rest/?method=Report.Queue".to_string();

let json = chilkat::JsonObject::new();
let _ = json.update_string("reportDescription.reportSuiteID", "rsid");
let _ = json.update_string("reportDescription.dateGranularity", "hour");

let http = chilkat::Http::new();

let dt = chilkat::DateTime::new();
let _ = dt.set_from_current_system_time();
let timecreated = dt.get_as_timestamp(false).unwrap_or_default();

let prng = chilkat::Prng::new();
let nonce = prng.gen_random(12, "hex").unwrap_or_default();

let secret = "SECRET".to_string();

let sb = chilkat::StringBuilder::new();
let _ = sb.append(&nonce);
let _ = sb.append(&timecreated);
let _ = sb.append(&secret);

let crypt = chilkat::Crypt2::new();
crypt.set_hash_algorithm("sha1");
crypt.set_encoding_mode("base64");
let digest = crypt.hash_string_enc(&sb.get_as_string().unwrap_or_default()).unwrap_or_default();

let sb_nonce = chilkat::StringBuilder::new();
let _ = sb_nonce.append(&nonce);
let _ = sb_nonce.encode("base64", "utf-8");

sb.clear();
let _ = sb.append("UsernameToken Username=\"USERNAME\", PasswordDigest=\"");
let _ = sb.append(&digest);
let _ = sb.append("\", Nonce=\"");
let _ = sb.append(&sb_nonce.get_as_string().unwrap_or_default());
let _ = sb.append("\", Created=\"");
let _ = sb.append(&timecreated);
let _ = sb.append("\"");

println!("{}", sb.get_as_string().unwrap_or_default());

http.set_request_header("X-WSSE", &sb.get_as_string().unwrap_or_default());

let resp = chilkat::HttpResponse::new();
if http.http_json("POST", &url, &json, "text/json", &resp).is_err() {
    println!("{}", http.last_error_text());
    return;
}

println!("Http Status code: {}", resp.status_code());
println!("JSON response:");
println!("{}", resp.body_str());