Chilkat Online Tools

GetGraphqlApi SQL Server Example

AWS AppSync

CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @sTmp0 nvarchar(max)
    -- This example requires the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @rest int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Rest', @rest OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    DECLARE @authAws int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.AuthAws', @authAws OUT

    EXEC sp_OASetProperty @authAws, 'AccessKey', 'AWS_ACCESS_KEY'
    EXEC sp_OASetProperty @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.)
    EXEC sp_OASetProperty @authAws, 'Region', 'us-west-2'
    EXEC sp_OASetProperty @authAws, 'ServiceName', 'appsync'
    -- SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    EXEC sp_OAMethod @rest, 'SetAuthAws', @success OUT, @authAws

    -- URL: https://appsync.us-west-2.amazonaws.com/
    -- Use the same region as specified above.
    EXEC sp_OAMethod @rest, 'Connect', @success OUT, 'appsync.us-west-2.amazonaws.com', 443, 1, 1
    IF @success <> 1
      BEGIN

        EXEC sp_OAGetProperty @rest, 'ConnectFailReason', @iTmp0 OUT
        PRINT 'ConnectFailReason: ' + @iTmp0
        EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @authAws
        RETURN
      END

    EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'Content-Type', 'application/x-amz-json-1.1'
    EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'X-Amz-Target', 'GetGraphqlApi'

    DECLARE @sbResponseBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @rest, 'FullRequestNoBodySb', @success OUT, 'GET', '/v1/apis/{apiId}', @sbResponseBody
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @authAws
        EXEC @hr = sp_OADestroy @sbResponseBody
        RETURN
      END
    DECLARE @respStatusCode int
    EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @respStatusCode OUT

    PRINT 'response status code = ' + @respStatusCode
    IF @respStatusCode <> 200
      BEGIN

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @rest, 'ResponseHeader', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Response Body:'
        EXEC sp_OAMethod @sbResponseBody, 'GetAsString', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @authAws
        EXEC @hr = sp_OADestroy @sbResponseBody
        RETURN
      END

    DECLARE @jResp int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @jResp OUT

    EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @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

    DECLARE @authenticationType nvarchar(max)

    DECLARE @lambdaAuthorizerConfigAuthorizerResultTtlInSeconds int

    DECLARE @lambdaAuthorizerConfigAuthorizerUri nvarchar(max)

    DECLARE @lambdaAuthorizerConfigIdentityValidationExpression nvarchar(max)

    DECLARE @openIDConnectConfigAuthTTL int

    DECLARE @openIDConnectConfigClientId nvarchar(max)

    DECLARE @openIDConnectConfigIatTTL int

    DECLARE @openIDConnectConfigIssuer nvarchar(max)

    DECLARE @userPoolConfigAppIdClientRegex nvarchar(max)

    DECLARE @userPoolConfigAwsRegion nvarchar(max)

    DECLARE @userPoolConfigUserPoolId nvarchar(max)

    DECLARE @ApiId nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @ApiId OUT, 'graphqlApi.apiId'
    DECLARE @Arn nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @Arn OUT, 'graphqlApi.arn'
    DECLARE @AuthenticationType nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @AuthenticationType OUT, 'graphqlApi.authenticationType'
    DECLARE @AuthorizerResultTtlInSeconds int
    EXEC sp_OAMethod @jResp, 'IntOf', @AuthorizerResultTtlInSeconds OUT, 'graphqlApi.lambdaAuthorizerConfig.authorizerResultTtlInSeconds'
    DECLARE @AuthorizerUri nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @AuthorizerUri OUT, 'graphqlApi.lambdaAuthorizerConfig.authorizerUri'
    DECLARE @IdentityValidationExpression nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @IdentityValidationExpression OUT, 'graphqlApi.lambdaAuthorizerConfig.identityValidationExpression'
    DECLARE @CloudWatchLogsRoleArn nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @CloudWatchLogsRoleArn OUT, 'graphqlApi.logConfig.cloudWatchLogsRoleArn'
    DECLARE @ExcludeVerboseContent int
    EXEC sp_OAMethod @jResp, 'IntOf', @ExcludeVerboseContent OUT, 'graphqlApi.logConfig.excludeVerboseContent'
    DECLARE @FieldLogLevel nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @FieldLogLevel OUT, 'graphqlApi.logConfig.fieldLogLevel'
    DECLARE @Name nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @Name OUT, 'graphqlApi.name'
    DECLARE @AuthTTL int
    EXEC sp_OAMethod @jResp, 'IntOf', @AuthTTL OUT, 'graphqlApi.openIDConnectConfig.authTTL'
    DECLARE @ClientId nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @ClientId OUT, 'graphqlApi.openIDConnectConfig.clientId'
    DECLARE @IatTTL int
    EXEC sp_OAMethod @jResp, 'IntOf', @IatTTL OUT, 'graphqlApi.openIDConnectConfig.iatTTL'
    DECLARE @Issuer nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @Issuer OUT, 'graphqlApi.openIDConnectConfig.issuer'
    DECLARE @v_String nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @v_String OUT, 'graphqlApi.tags.string'
    DECLARE @UrisString nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @UrisString OUT, 'graphqlApi.uris.string'
    DECLARE @AppIdClientRegex nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @AppIdClientRegex OUT, 'graphqlApi.userPoolConfig.appIdClientRegex'
    DECLARE @AwsRegion nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @AwsRegion OUT, 'graphqlApi.userPoolConfig.awsRegion'
    DECLARE @DefaultAction nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @DefaultAction OUT, 'graphqlApi.userPoolConfig.defaultAction'
    DECLARE @UserPoolId nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @UserPoolId OUT, 'graphqlApi.userPoolConfig.userPoolId'
    DECLARE @WafWebAclArn nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @WafWebAclArn OUT, 'graphqlApi.wafWebAclArn'
    DECLARE @XrayEnabled int
    EXEC sp_OAMethod @jResp, 'IntOf', @XrayEnabled OUT, 'graphqlApi.xrayEnabled'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'graphqlApi.additionalAuthenticationProviders'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @authenticationType OUT, 'graphqlApi.additionalAuthenticationProviders[i].authenticationType'
        EXEC sp_OAMethod @jResp, 'IntOf', @lambdaAuthorizerConfigAuthorizerResultTtlInSeconds OUT, 'graphqlApi.additionalAuthenticationProviders[i].lambdaAuthorizerConfig.authorizerResultTtlInSeconds'
        EXEC sp_OAMethod @jResp, 'StringOf', @lambdaAuthorizerConfigAuthorizerUri OUT, 'graphqlApi.additionalAuthenticationProviders[i].lambdaAuthorizerConfig.authorizerUri'
        EXEC sp_OAMethod @jResp, 'StringOf', @lambdaAuthorizerConfigIdentityValidationExpression OUT, 'graphqlApi.additionalAuthenticationProviders[i].lambdaAuthorizerConfig.identityValidationExpression'
        EXEC sp_OAMethod @jResp, 'IntOf', @openIDConnectConfigAuthTTL OUT, 'graphqlApi.additionalAuthenticationProviders[i].openIDConnectConfig.authTTL'
        EXEC sp_OAMethod @jResp, 'StringOf', @openIDConnectConfigClientId OUT, 'graphqlApi.additionalAuthenticationProviders[i].openIDConnectConfig.clientId'
        EXEC sp_OAMethod @jResp, 'IntOf', @openIDConnectConfigIatTTL OUT, 'graphqlApi.additionalAuthenticationProviders[i].openIDConnectConfig.iatTTL'
        EXEC sp_OAMethod @jResp, 'StringOf', @openIDConnectConfigIssuer OUT, 'graphqlApi.additionalAuthenticationProviders[i].openIDConnectConfig.issuer'
        EXEC sp_OAMethod @jResp, 'StringOf', @userPoolConfigAppIdClientRegex OUT, 'graphqlApi.additionalAuthenticationProviders[i].userPoolConfig.appIdClientRegex'
        EXEC sp_OAMethod @jResp, 'StringOf', @userPoolConfigAwsRegion OUT, 'graphqlApi.additionalAuthenticationProviders[i].userPoolConfig.awsRegion'
        EXEC sp_OAMethod @jResp, 'StringOf', @userPoolConfigUserPoolId OUT, 'graphqlApi.additionalAuthenticationProviders[i].userPoolConfig.userPoolId'
        SELECT @i = @i + 1
      END

    -- 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
    --   }
    -- }

    EXEC @hr = sp_OADestroy @rest
    EXEC @hr = sp_OADestroy @authAws
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp


END
GO