Sample code for 30+ languages & platforms
Objective-C

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 Objective-C Downloads

Objective-C
#import <NSString.h>
#import <CkoJsonObject.h>
#import <CkoHttp.h>
#import <CkoDateTime.h>
#import <CkoPrng.h>
#import <CkoStringBuilder.h>
#import <CkoCrypt2.h>
#import <CkoHttpResponse.h>

BOOL success = NO;

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

CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"reportDescription.reportSuiteID" value: @"rsid"];
[json UpdateString: @"reportDescription.dateGranularity" value: @"hour"];

CkoHttp *http = [[CkoHttp alloc] init];

CkoDateTime *dt = [[CkoDateTime alloc] init];
[dt SetFromCurrentSystemTime];
NSString *timecreated = [dt GetAsTimestamp: NO];

CkoPrng *prng = [[CkoPrng alloc] init];
NSString *nonce = [prng GenRandom: [NSNumber numberWithInt: 12] encoding: @"hex"];

NSString *secret = @"SECRET";

CkoStringBuilder *sb = [[CkoStringBuilder alloc] init];
[sb Append: nonce];
[sb Append: timecreated];
[sb Append: secret];

CkoCrypt2 *crypt = [[CkoCrypt2 alloc] init];
crypt.HashAlgorithm = @"sha1";
crypt.EncodingMode = @"base64";
NSString *digest = [crypt HashStringENC: [sb GetAsString]];

CkoStringBuilder *sbNonce = [[CkoStringBuilder alloc] init];
[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: @"\""];

NSLog(@"%@",[sb GetAsString]);

[http SetRequestHeader: @"X-WSSE" value: [sb GetAsString]];

CkoHttpResponse *resp = [[CkoHttpResponse alloc] init];
success = [http HttpJson: @"POST" url: url json: json contentType: @"text/json" response: resp];
if (success == NO) {
    NSLog(@"%@",http.LastErrorText);
    return;
}

NSLog(@"%@%d",@"Http Status code: ",[resp.StatusCode intValue]);
NSLog(@"%@",@"JSON response:");
NSLog(@"%@",resp.BodyStr);