Chilkat Online Tools

DescribeUserHierarchyGroup Objective-C Example

Amazon Connect

#import <CkoRest.h>
#import <CkoAuthAws.h>
#import <CkoStringBuilder.h>
#import <CkoJsonObject.h>
#import <NSString.h>

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

CkoRest *rest = [[CkoRest alloc] init];
BOOL success;

CkoAuthAws *authAws = [[CkoAuthAws alloc] init];
authAws.AccessKey = @"AWS_ACCESS_KEY";
authAws.SecretKey = @"AWS_SECRET_KEY";

// Don't forget to change the region to your particular region. (Also make the same change in the call to Connect below.)
authAws.Region = @"us-west-2";
authAws.ServiceName = @"connect";
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
[rest SetAuthAws: authAws];

// URL: https://connect.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = [rest Connect: @"connect.us-west-2.amazonaws.com" port: [NSNumber numberWithInt: 443] tls: YES autoReconnect: YES];
if (success != YES) {
    NSLog(@"%@%d",@"ConnectFailReason: ",[rest.ConnectFailReason intValue]);
    NSLog(@"%@",rest.LastErrorText);
    return;
}

[rest AddHeader: @"Content-Type" value: @"application/x-amz-json-1.1"];
[rest AddHeader: @"X-Amz-Target" value: @"DescribeUserHierarchyGroup"];

CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [rest FullRequestNoBodySb: @"GET" uriPath: @"/user-hierarchy-groups/{InstanceId}/{HierarchyGroupId}" sb: sbResponseBody];
if (success != YES) {
    NSLog(@"%@",rest.LastErrorText);
    return;
}

int respStatusCode = [rest.ResponseStatusCode intValue];
NSLog(@"%@%d",@"response status code = ",respStatusCode);
if (respStatusCode != 200) {
    NSLog(@"%@",@"Response Header:");
    NSLog(@"%@",rest.ResponseHeader);
    NSLog(@"%@",@"Response Body:");
    NSLog(@"%@",[sbResponseBody GetAsString]);
    return;
}

CkoJsonObject *jResp = [[CkoJsonObject alloc] init];
[jResp LoadSb: sbResponseBody];

// The following code parses the JSON response.
// A sample JSON response is shown below the sample code.

// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON

NSString *Arn = [jResp StringOf: @"HierarchyGroup.Arn"];
NSString *LevelFiveArn = [jResp StringOf: @"HierarchyGroup.HierarchyPath.LevelFive.Arn"];
NSString *Id = [jResp StringOf: @"HierarchyGroup.HierarchyPath.LevelFive.Id"];
NSString *Name = [jResp StringOf: @"HierarchyGroup.HierarchyPath.LevelFive.Name"];
NSString *LevelFourArn = [jResp StringOf: @"HierarchyGroup.HierarchyPath.LevelFour.Arn"];
NSString *LevelFourId = [jResp StringOf: @"HierarchyGroup.HierarchyPath.LevelFour.Id"];
NSString *LevelFourName = [jResp StringOf: @"HierarchyGroup.HierarchyPath.LevelFour.Name"];
NSString *LevelOneArn = [jResp StringOf: @"HierarchyGroup.HierarchyPath.LevelOne.Arn"];
NSString *LevelOneId = [jResp StringOf: @"HierarchyGroup.HierarchyPath.LevelOne.Id"];
NSString *LevelOneName = [jResp StringOf: @"HierarchyGroup.HierarchyPath.LevelOne.Name"];
NSString *LevelThreeArn = [jResp StringOf: @"HierarchyGroup.HierarchyPath.LevelThree.Arn"];
NSString *LevelThreeId = [jResp StringOf: @"HierarchyGroup.HierarchyPath.LevelThree.Id"];
NSString *LevelThreeName = [jResp StringOf: @"HierarchyGroup.HierarchyPath.LevelThree.Name"];
NSString *LevelTwoArn = [jResp StringOf: @"HierarchyGroup.HierarchyPath.LevelTwo.Arn"];
NSString *LevelTwoId = [jResp StringOf: @"HierarchyGroup.HierarchyPath.LevelTwo.Id"];
NSString *LevelTwoName = [jResp StringOf: @"HierarchyGroup.HierarchyPath.LevelTwo.Name"];
NSString *HierarchyGroupId = [jResp StringOf: @"HierarchyGroup.Id"];
NSString *LevelId = [jResp StringOf: @"HierarchyGroup.LevelId"];
NSString *HierarchyGroupName = [jResp StringOf: @"HierarchyGroup.Name"];
NSString *v_String = [jResp StringOf: @"HierarchyGroup.Tags.string"];

// A sample JSON response body parsed by the above code:

// {
//   "HierarchyGroup": {
//     "Arn": "string",
//     "HierarchyPath": {
//       "LevelFive": {
//         "Arn": "string",
//         "Id": "string",
//         "Name": "string"
//       },
//       "LevelFour": {
//         "Arn": "string",
//         "Id": "string",
//         "Name": "string"
//       },
//       "LevelOne": {
//         "Arn": "string",
//         "Id": "string",
//         "Name": "string"
//       },
//       "LevelThree": {
//         "Arn": "string",
//         "Id": "string",
//         "Name": "string"
//       },
//       "LevelTwo": {
//         "Arn": "string",
//         "Id": "string",
//         "Name": "string"
//       }
//     },
//     "Id": "string",
//     "LevelId": "string",
//     "Name": "string",
//     "Tags": {
//       "string": "string"
//     }
//   }
// }