Perl
Perl
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 Perl Downloads
use strict;
use warnings;
use Chilkat2;
# 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
my $url = 'https://api.omniture.com/admin/1.4/rest/?method=Report.Queue';
my $json = Chilkat2::JsonObject->new;
$json->UpdateString('reportDescription.reportSuiteID', 'rsid');
$json->UpdateString('reportDescription.dateGranularity', 'hour');
my $http = Chilkat2::Http->new;
my $dt = Chilkat2::DateTime->new;
$dt->SetFromCurrentSystemTime();
my $timecreated = $dt->GetAsTimestamp(0);
my $prng = Chilkat2::Prng->new;
my $nonce = $prng->GenRandom(12, 'hex');
my $secret = 'SECRET';
my $sb = Chilkat2::StringBuilder->new;
$sb->Append($nonce);
$sb->Append($timecreated);
$sb->Append($secret);
my $crypt = Chilkat2::Crypt2->new;
$crypt->HashAlgorithm('sha1');
$crypt->EncodingMode('base64');
my $digest = $crypt->HashStringENC($sb->GetAsString());
my $sbNonce = Chilkat2::StringBuilder->new;
$sbNonce->Append($nonce);
$sbNonce->Encode('base64', 'utf-8');
$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('"');
print $sb->GetAsString(), "\n";
$http->SetRequestHeader('X-WSSE', $sb->GetAsString());
my $resp = Chilkat2::HttpResponse->new;
my $success = $http->HttpJson('POST', $url, $json, 'text/json', $resp);
if (!$success) {
print $http->LastErrorText, "\n";
exit;
}
print 'Http Status code: ', $resp->StatusCode, "\n";
print "JSON response:\n";
print $resp->BodyStr, "\n";