Sample code for 30+ languages & platforms
JavaScript

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)
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat v11.4.0 or greater.
JavaScript
var success = false;

// 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
var url = "https://api.omniture.com/admin/1.4/rest/?method=Report.Queue";

var json = new CkJsonObject();
json.UpdateString("reportDescription.reportSuiteID","rsid");
json.UpdateString("reportDescription.dateGranularity","hour");

var http = new CkHttp();

var dt = new CkDateTime();
dt.SetFromCurrentSystemTime();
var timecreated = dt.GetAsTimestamp(false);

var prng = new CkPrng();
var nonce = prng.GenRandom(12,"hex");

var secret = "SECRET";

var sb = new CkStringBuilder();
sb.Append(nonce);
sb.Append(timecreated);
sb.Append(secret);

var crypt = new CkCrypt2();
crypt.HashAlgorithm = "sha1";
crypt.EncodingMode = "base64";
var digest = crypt.HashStringENC(sb.GetAsString());

var sbNonce = new CkStringBuilder();
sbNonce.Append(nonce);
sbNonce.Encode("base64");

sb.Clear();
sb.Append("UsernameToken Username=\"USERNAME\", PasswordDigest=\"");
sb.Append(digest);
sb.Append("\", Nonce=\"");
sb.Append(sbNonce.GetAsString());
sb.Append("\", Created=\"");
sb.Append(timecreated);
sb.Append("\"");

console.log(sb.GetAsString());

http.SetRequestHeader("X-WSSE",sb.GetAsString());

var resp = new CkHttpResponse();
success = http.HttpJson("POST",url,json,"text/json",resp);
if (success == false) {
    console.log(http.LastErrorText);
    return;
}

console.log("Http Status code: " + resp.StatusCode);
console.log("JSON response:");
console.log(resp.BodyStr);