Zig
Zig
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 Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// 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
const url = "https://api.omniture.com/admin/1.4/rest/?method=Report.Queue";
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.updateString("reportDescription.reportSuiteID", "rsid") catch {};
json.updateString("reportDescription.dateGranularity", "hour") catch {};
const http = try chilkat.Http.init();
defer http.deinit();
const dt = try chilkat.DateTime.init();
defer dt.deinit();
dt.setFromCurrentSystemTime() catch {};
const timecreated = try dt.getAsTimestamp(alloc, false);
const prng = try chilkat.Prng.init();
defer prng.deinit();
const nonce = try prng.genRandom(alloc, 12, "hex");
const secret = "SECRET";
const sb = try chilkat.StringBuilder.init();
defer sb.deinit();
sb.append(nonce) catch {};
sb.append(timecreated) catch {};
sb.append(secret) catch {};
const crypt = try chilkat.Crypt2.init();
defer crypt.deinit();
crypt.setHashAlgorithm("sha1");
crypt.setEncodingMode("base64");
const digest = try crypt.hashStringENC(alloc, try sb.getAsString(alloc));
const sb_nonce = try chilkat.StringBuilder.init();
defer sb_nonce.deinit();
sb_nonce.append(nonce) catch {};
sb_nonce.encode("base64", "utf-8") catch {};
sb.clear();
sb.append("UsernameToken Username=\"USERNAME\", PasswordDigest=\"") catch {};
sb.append(digest) catch {};
sb.append("\", Nonce=\"") catch {};
sb.append(try sb_nonce.getAsString(alloc)) catch {};
sb.append("\", Created=\"") catch {};
sb.append(timecreated) catch {};
sb.append("\"") catch {};
std.debug.print("{s}\n", .{try sb.getAsString(alloc)});
http.setRequestHeader("X-WSSE", try sb.getAsString(alloc));
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpJson("POST", url, json, "text/json", resp) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
std.debug.print("Http Status code: {d}\n", .{resp.getStatusCode()});
std.debug.print("JSON response:\n", .{});
std.debug.print("{s}\n", .{try resp.getBodyStr(alloc)});
}