Chilkat Online Tools

UpdateGraphqlApi Swift3 Example

AWS AppSync

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

    let rest = CkoRest()!
    var success: Bool

    let authAws = CkoAuthAws()!
    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: 443, tls: true, autoReconnect: true)
    if success != true {
        print("ConnectFailReason: \(rest.connectFailReason.intValue)")
        print("\(rest.lastErrorText!)")
        return
    }

    // The following code creates the JSON request body.
    // The JSON created by this code is shown below.

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

    let json = CkoJsonObject()!
    json.update("additionalAuthenticationProviders[0].authenticationType", value: "string")
    json.updateInt("additionalAuthenticationProviders[0].lambdaAuthorizerConfig.authorizerResultTtlInSeconds", value: 123)
    json.update("additionalAuthenticationProviders[0].lambdaAuthorizerConfig.authorizerUri", value: "string")
    json.update("additionalAuthenticationProviders[0].lambdaAuthorizerConfig.identityValidationExpression", value: "string")
    json.updateInt("additionalAuthenticationProviders[0].openIDConnectConfig.authTTL", value: 123)
    json.update("additionalAuthenticationProviders[0].openIDConnectConfig.clientId", value: "string")
    json.updateInt("additionalAuthenticationProviders[0].openIDConnectConfig.iatTTL", value: 123)
    json.update("additionalAuthenticationProviders[0].openIDConnectConfig.issuer", value: "string")
    json.update("additionalAuthenticationProviders[0].userPoolConfig.appIdClientRegex", value: "string")
    json.update("additionalAuthenticationProviders[0].userPoolConfig.awsRegion", value: "string")
    json.update("additionalAuthenticationProviders[0].userPoolConfig.userPoolId", value: "string")
    json.update("authenticationType", value: "string")
    json.updateInt("lambdaAuthorizerConfig.authorizerResultTtlInSeconds", value: 123)
    json.update("lambdaAuthorizerConfig.authorizerUri", value: "string")
    json.update("lambdaAuthorizerConfig.identityValidationExpression", value: "string")
    json.update("logConfig.cloudWatchLogsRoleArn", value: "string")
    json.updateInt("logConfig.excludeVerboseContent", value: 123)
    json.update("logConfig.fieldLogLevel", value: "string")
    json.update("name", value: "string")
    json.updateInt("openIDConnectConfig.authTTL", value: 123)
    json.update("openIDConnectConfig.clientId", value: "string")
    json.updateInt("openIDConnectConfig.iatTTL", value: 123)
    json.update("openIDConnectConfig.issuer", value: "string")
    json.update("userPoolConfig.appIdClientRegex", value: "string")
    json.update("userPoolConfig.awsRegion", value: "string")
    json.update("userPoolConfig.defaultAction", value: "string")
    json.update("userPoolConfig.userPoolId", value: "string")
    json.updateInt("xrayEnabled", value: 123)

    // The JSON request body created by the above code:

    // {
    //   "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"
    //       }
    //     }
    //   ],
    //   "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"
    //   },
    //   "userPoolConfig": {
    //     "appIdClientRegex": "string",
    //     "awsRegion": "string",
    //     "defaultAction": "string",
    //     "userPoolId": "string"
    //   },
    //   "xrayEnabled": boolean
    // }

    rest.addHeader("Content-Type", value: "application/x-amz-json-1.1")
    rest.addHeader("X-Amz-Target", value: "UpdateGraphqlApi")

    let sbRequestBody = CkoStringBuilder()!
    json.emitSb(sbRequestBody)
    let sbResponseBody = CkoStringBuilder()!
    success = rest.fullRequestSb("POST", uriPath: "/v1/apis/{apiId}", requestBody: sbRequestBody, responseBody: sbResponseBody)
    if success != true {
        print("\(rest.lastErrorText!)")
        return
    }

    var respStatusCode: Int = rest.responseStatusCode.intValue
    print("response status code = \(respStatusCode)")
    if respStatusCode != 200 {
        print("Response Header:")
        print("\(rest.responseHeader!)")
        print("Response Body:")
        print("\(sbResponseBody.getAsString()!)")
        return
    }

    let jResp = CkoJsonObject()!
    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

    var authenticationType: String?
    var lambdaAuthorizerConfigAuthorizerResultTtlInSeconds: Int
    var lambdaAuthorizerConfigAuthorizerUri: String?
    var lambdaAuthorizerConfigIdentityValidationExpression: String?
    var openIDConnectConfigAuthTTL: Int
    var openIDConnectConfigClientId: String?
    var openIDConnectConfigIatTTL: Int
    var openIDConnectConfigIssuer: String?
    var userPoolConfigAppIdClientRegex: String?
    var userPoolConfigAwsRegion: String?
    var userPoolConfigUserPoolId: String?

    var ApiId: String? = jResp.string(of: "graphqlApi.apiId")
    var Arn: String? = jResp.string(of: "graphqlApi.arn")
    var AuthenticationType: String? = jResp.string(of: "graphqlApi.authenticationType")
    var AuthorizerResultTtlInSeconds: Int = jResp.int(of: "graphqlApi.lambdaAuthorizerConfig.authorizerResultTtlInSeconds").intValue
    var AuthorizerUri: String? = jResp.string(of: "graphqlApi.lambdaAuthorizerConfig.authorizerUri")
    var IdentityValidationExpression: String? = jResp.string(of: "graphqlApi.lambdaAuthorizerConfig.identityValidationExpression")
    var CloudWatchLogsRoleArn: String? = jResp.string(of: "graphqlApi.logConfig.cloudWatchLogsRoleArn")
    var ExcludeVerboseContent: Int = jResp.int(of: "graphqlApi.logConfig.excludeVerboseContent").intValue
    var FieldLogLevel: String? = jResp.string(of: "graphqlApi.logConfig.fieldLogLevel")
    var Name: String? = jResp.string(of: "graphqlApi.name")
    var AuthTTL: Int = jResp.int(of: "graphqlApi.openIDConnectConfig.authTTL").intValue
    var ClientId: String? = jResp.string(of: "graphqlApi.openIDConnectConfig.clientId")
    var IatTTL: Int = jResp.int(of: "graphqlApi.openIDConnectConfig.iatTTL").intValue
    var Issuer: String? = jResp.string(of: "graphqlApi.openIDConnectConfig.issuer")
    var v_String: String? = jResp.string(of: "graphqlApi.tags.string")
    var UrisString: String? = jResp.string(of: "graphqlApi.uris.string")
    var AppIdClientRegex: String? = jResp.string(of: "graphqlApi.userPoolConfig.appIdClientRegex")
    var AwsRegion: String? = jResp.string(of: "graphqlApi.userPoolConfig.awsRegion")
    var DefaultAction: String? = jResp.string(of: "graphqlApi.userPoolConfig.defaultAction")
    var UserPoolId: String? = jResp.string(of: "graphqlApi.userPoolConfig.userPoolId")
    var WafWebAclArn: String? = jResp.string(of: "graphqlApi.wafWebAclArn")
    var XrayEnabled: Int = jResp.int(of: "graphqlApi.xrayEnabled").intValue
    var i: Int = 0
    var count_i: Int = jResp.size(ofArray: "graphqlApi.additionalAuthenticationProviders").intValue
    while i < count_i {
        jResp.i = i
        authenticationType = jResp.string(of: "graphqlApi.additionalAuthenticationProviders[i].authenticationType")
        lambdaAuthorizerConfigAuthorizerResultTtlInSeconds = jResp.int(of: "graphqlApi.additionalAuthenticationProviders[i].lambdaAuthorizerConfig.authorizerResultTtlInSeconds").intValue
        lambdaAuthorizerConfigAuthorizerUri = jResp.string(of: "graphqlApi.additionalAuthenticationProviders[i].lambdaAuthorizerConfig.authorizerUri")
        lambdaAuthorizerConfigIdentityValidationExpression = jResp.string(of: "graphqlApi.additionalAuthenticationProviders[i].lambdaAuthorizerConfig.identityValidationExpression")
        openIDConnectConfigAuthTTL = jResp.int(of: "graphqlApi.additionalAuthenticationProviders[i].openIDConnectConfig.authTTL").intValue
        openIDConnectConfigClientId = jResp.string(of: "graphqlApi.additionalAuthenticationProviders[i].openIDConnectConfig.clientId")
        openIDConnectConfigIatTTL = jResp.int(of: "graphqlApi.additionalAuthenticationProviders[i].openIDConnectConfig.iatTTL").intValue
        openIDConnectConfigIssuer = jResp.string(of: "graphqlApi.additionalAuthenticationProviders[i].openIDConnectConfig.issuer")
        userPoolConfigAppIdClientRegex = jResp.string(of: "graphqlApi.additionalAuthenticationProviders[i].userPoolConfig.appIdClientRegex")
        userPoolConfigAwsRegion = jResp.string(of: "graphqlApi.additionalAuthenticationProviders[i].userPoolConfig.awsRegion")
        userPoolConfigUserPoolId = jResp.string(of: "graphqlApi.additionalAuthenticationProviders[i].userPoolConfig.userPoolId")
        i = i + 1
    }

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

    // {
    //   "graphqlApi": {
    //     "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
    //   }
    // }

}