Chilkat Online Tools

ListGraphqlApis Objective-C Example

AWS AppSync

#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 = @"appsync";
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
[rest SetAuthAws: authAws];

// URL: https://appsync.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = [rest Connect: @"appsync.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: @"ListGraphqlApis"];

CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [rest FullRequestNoBodySb: @"GET" uriPath: @"/v1/apis" 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 *apiId = 0;
NSString *arn = 0;
NSString *authenticationType = 0;
int AuthorizerResultTtlInSeconds;
NSString *AuthorizerUri = 0;
NSString *IdentityValidationExpression = 0;
NSString *CloudWatchLogsRoleArn = 0;
int ExcludeVerboseContent;
NSString *FieldLogLevel = 0;
NSString *name = 0;
int AuthTTL;
NSString *ClientId = 0;
int IatTTL;
NSString *Issuer = 0;
NSString *v_String = 0;
NSString *urisString = 0;
NSString *AppIdClientRegex = 0;
NSString *AwsRegion = 0;
NSString *DefaultAction = 0;
NSString *UserPoolId = 0;
NSString *wafWebAclArn = 0;
int xrayEnabled;
int j;
int count_j;
int lambdaAuthorizerConfigAuthorizerResultTtlInSeconds;
NSString *lambdaAuthorizerConfigAuthorizerUri = 0;
NSString *lambdaAuthorizerConfigIdentityValidationExpression = 0;
int openIDConnectConfigAuthTTL;
NSString *openIDConnectConfigClientId = 0;
int openIDConnectConfigIatTTL;
NSString *openIDConnectConfigIssuer = 0;
NSString *userPoolConfigAppIdClientRegex = 0;
NSString *userPoolConfigAwsRegion = 0;
NSString *userPoolConfigUserPoolId = 0;

NSString *nextToken = [jResp StringOf: @"nextToken"];
int i = 0;
int count_i = [[jResp SizeOfArray: @"graphqlApis"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    apiId = [jResp StringOf: @"graphqlApis[i].apiId"];
    arn = [jResp StringOf: @"graphqlApis[i].arn"];
    authenticationType = [jResp StringOf: @"graphqlApis[i].authenticationType"];
    AuthorizerResultTtlInSeconds = [[jResp IntOf: @"graphqlApis[i].lambdaAuthorizerConfig.authorizerResultTtlInSeconds"] intValue];
    AuthorizerUri = [jResp StringOf: @"graphqlApis[i].lambdaAuthorizerConfig.authorizerUri"];
    IdentityValidationExpression = [jResp StringOf: @"graphqlApis[i].lambdaAuthorizerConfig.identityValidationExpression"];
    CloudWatchLogsRoleArn = [jResp StringOf: @"graphqlApis[i].logConfig.cloudWatchLogsRoleArn"];
    ExcludeVerboseContent = [[jResp IntOf: @"graphqlApis[i].logConfig.excludeVerboseContent"] intValue];
    FieldLogLevel = [jResp StringOf: @"graphqlApis[i].logConfig.fieldLogLevel"];
    name = [jResp StringOf: @"graphqlApis[i].name"];
    AuthTTL = [[jResp IntOf: @"graphqlApis[i].openIDConnectConfig.authTTL"] intValue];
    ClientId = [jResp StringOf: @"graphqlApis[i].openIDConnectConfig.clientId"];
    IatTTL = [[jResp IntOf: @"graphqlApis[i].openIDConnectConfig.iatTTL"] intValue];
    Issuer = [jResp StringOf: @"graphqlApis[i].openIDConnectConfig.issuer"];
    v_String = [jResp StringOf: @"graphqlApis[i].tags.string"];
    urisString = [jResp StringOf: @"graphqlApis[i].uris.string"];
    AppIdClientRegex = [jResp StringOf: @"graphqlApis[i].userPoolConfig.appIdClientRegex"];
    AwsRegion = [jResp StringOf: @"graphqlApis[i].userPoolConfig.awsRegion"];
    DefaultAction = [jResp StringOf: @"graphqlApis[i].userPoolConfig.defaultAction"];
    UserPoolId = [jResp StringOf: @"graphqlApis[i].userPoolConfig.userPoolId"];
    wafWebAclArn = [jResp StringOf: @"graphqlApis[i].wafWebAclArn"];
    xrayEnabled = [[jResp IntOf: @"graphqlApis[i].xrayEnabled"] intValue];
    j = 0;
    count_j = [[jResp SizeOfArray: @"graphqlApis[i].additionalAuthenticationProviders"] intValue];
    while (j < count_j) {
        jResp.J = [NSNumber numberWithInt: j];
        authenticationType = [jResp StringOf: @"graphqlApis[i].additionalAuthenticationProviders[j].authenticationType"];
        lambdaAuthorizerConfigAuthorizerResultTtlInSeconds = [[jResp IntOf: @"graphqlApis[i].additionalAuthenticationProviders[j].lambdaAuthorizerConfig.authorizerResultTtlInSeconds"] intValue];
        lambdaAuthorizerConfigAuthorizerUri = [jResp StringOf: @"graphqlApis[i].additionalAuthenticationProviders[j].lambdaAuthorizerConfig.authorizerUri"];
        lambdaAuthorizerConfigIdentityValidationExpression = [jResp StringOf: @"graphqlApis[i].additionalAuthenticationProviders[j].lambdaAuthorizerConfig.identityValidationExpression"];
        openIDConnectConfigAuthTTL = [[jResp IntOf: @"graphqlApis[i].additionalAuthenticationProviders[j].openIDConnectConfig.authTTL"] intValue];
        openIDConnectConfigClientId = [jResp StringOf: @"graphqlApis[i].additionalAuthenticationProviders[j].openIDConnectConfig.clientId"];
        openIDConnectConfigIatTTL = [[jResp IntOf: @"graphqlApis[i].additionalAuthenticationProviders[j].openIDConnectConfig.iatTTL"] intValue];
        openIDConnectConfigIssuer = [jResp StringOf: @"graphqlApis[i].additionalAuthenticationProviders[j].openIDConnectConfig.issuer"];
        userPoolConfigAppIdClientRegex = [jResp StringOf: @"graphqlApis[i].additionalAuthenticationProviders[j].userPoolConfig.appIdClientRegex"];
        userPoolConfigAwsRegion = [jResp StringOf: @"graphqlApis[i].additionalAuthenticationProviders[j].userPoolConfig.awsRegion"];
        userPoolConfigUserPoolId = [jResp StringOf: @"graphqlApis[i].additionalAuthenticationProviders[j].userPoolConfig.userPoolId"];
        j = j + 1;
    }

    i = i + 1;
}

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

// {
//   "graphqlApis": [
//     {
//       "additionalAuthenticationProviders": [
//         {
//           "authenticationType": "string",
//           "lambdaAuthorizerConfig": {
//             "authorizerResultTtlInSeconds": number,
//             "authorizerUri": "string",
//             "identityValidationExpression": "string"
//           },
//           "openIDConnectConfig": {
//             "authTTL": number,
//             "clientId": "string",
//             "iatTTL": number,
//             "issuer": "string"
//           },
//           "userPoolConfig": {
//             "appIdClientRegex": "string",
//             "awsRegion": "string",
//             "userPoolId": "string"
//           }
//         }
//       ],
//       "apiId": "string",
//       "arn": "string",
//       "authenticationType": "string",
//       "lambdaAuthorizerConfig": {
//         "authorizerResultTtlInSeconds": number,
//         "authorizerUri": "string",
//         "identityValidationExpression": "string"
//       },
//       "logConfig": {
//         "cloudWatchLogsRoleArn": "string",
//         "excludeVerboseContent": boolean,
//         "fieldLogLevel": "string"
//       },
//       "name": "string",
//       "openIDConnectConfig": {
//         "authTTL": number,
//         "clientId": "string",
//         "iatTTL": number,
//         "issuer": "string"
//       },
//       "tags": {
//         "string": "string"
//       },
//       "uris": {
//         "string": "string"
//       },
//       "userPoolConfig": {
//         "appIdClientRegex": "string",
//         "awsRegion": "string",
//         "defaultAction": "string",
//         "userPoolId": "string"
//       },
//       "wafWebAclArn": "string",
//       "xrayEnabled": boolean
//     }
//   ],
//   "nextToken": "string"
// }