ListDataSources SQL Server Example
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', 'ListDataSources'
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}/datasources', @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 @dataSourceArn nvarchar(max)
DECLARE @description nvarchar(max)
DECLARE @AwsRegion nvarchar(max)
DECLARE @BaseTableTTL int
DECLARE @DeltaSyncTableName nvarchar(max)
DECLARE @DeltaSyncTableTTL int
DECLARE @TableName nvarchar(max)
DECLARE @UseCallerCredentials int
DECLARE @Versioned int
DECLARE @elasticsearchConfigAwsRegion nvarchar(max)
DECLARE @Endpoint nvarchar(max)
DECLARE @AuthorizationType nvarchar(max)
DECLARE @SigningRegion nvarchar(max)
DECLARE @SigningServiceName nvarchar(max)
DECLARE @httpConfigEndpoint nvarchar(max)
DECLARE @LambdaFunctionArn nvarchar(max)
DECLARE @name nvarchar(max)
DECLARE @openSearchServiceConfigAwsRegion nvarchar(max)
DECLARE @openSearchServiceConfigEndpoint nvarchar(max)
DECLARE @RdsHttpEndpointConfigAwsRegion nvarchar(max)
DECLARE @AwsSecretStoreArn nvarchar(max)
DECLARE @DatabaseName nvarchar(max)
DECLARE @DbClusterIdentifier nvarchar(max)
DECLARE @Schema nvarchar(max)
DECLARE @RelationalDatabaseSourceType nvarchar(max)
DECLARE @serviceRoleArn nvarchar(max)
DECLARE @v_type nvarchar(max)
DECLARE @nextToken nvarchar(max)
EXEC sp_OAMethod @jResp, 'StringOf', @nextToken OUT, 'nextToken'
DECLARE @i int
SELECT @i = 0
DECLARE @count_i int
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'dataSources'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @jResp, 'I', @i
EXEC sp_OAMethod @jResp, 'StringOf', @dataSourceArn OUT, 'dataSources[i].dataSourceArn'
EXEC sp_OAMethod @jResp, 'StringOf', @description OUT, 'dataSources[i].description'
EXEC sp_OAMethod @jResp, 'StringOf', @AwsRegion OUT, 'dataSources[i].dynamodbConfig.awsRegion'
EXEC sp_OAMethod @jResp, 'IntOf', @BaseTableTTL OUT, 'dataSources[i].dynamodbConfig.deltaSyncConfig.baseTableTTL'
EXEC sp_OAMethod @jResp, 'StringOf', @DeltaSyncTableName OUT, 'dataSources[i].dynamodbConfig.deltaSyncConfig.deltaSyncTableName'
EXEC sp_OAMethod @jResp, 'IntOf', @DeltaSyncTableTTL OUT, 'dataSources[i].dynamodbConfig.deltaSyncConfig.deltaSyncTableTTL'
EXEC sp_OAMethod @jResp, 'StringOf', @TableName OUT, 'dataSources[i].dynamodbConfig.tableName'
EXEC sp_OAMethod @jResp, 'IntOf', @UseCallerCredentials OUT, 'dataSources[i].dynamodbConfig.useCallerCredentials'
EXEC sp_OAMethod @jResp, 'IntOf', @Versioned OUT, 'dataSources[i].dynamodbConfig.versioned'
EXEC sp_OAMethod @jResp, 'StringOf', @elasticsearchConfigAwsRegion OUT, 'dataSources[i].elasticsearchConfig.awsRegion'
EXEC sp_OAMethod @jResp, 'StringOf', @Endpoint OUT, 'dataSources[i].elasticsearchConfig.endpoint'
EXEC sp_OAMethod @jResp, 'StringOf', @AuthorizationType OUT, 'dataSources[i].httpConfig.authorizationConfig.authorizationType'
EXEC sp_OAMethod @jResp, 'StringOf', @SigningRegion OUT, 'dataSources[i].httpConfig.authorizationConfig.awsIamConfig.signingRegion'
EXEC sp_OAMethod @jResp, 'StringOf', @SigningServiceName OUT, 'dataSources[i].httpConfig.authorizationConfig.awsIamConfig.signingServiceName'
EXEC sp_OAMethod @jResp, 'StringOf', @httpConfigEndpoint OUT, 'dataSources[i].httpConfig.endpoint'
EXEC sp_OAMethod @jResp, 'StringOf', @LambdaFunctionArn OUT, 'dataSources[i].lambdaConfig.lambdaFunctionArn'
EXEC sp_OAMethod @jResp, 'StringOf', @name OUT, 'dataSources[i].name'
EXEC sp_OAMethod @jResp, 'StringOf', @openSearchServiceConfigAwsRegion OUT, 'dataSources[i].openSearchServiceConfig.awsRegion'
EXEC sp_OAMethod @jResp, 'StringOf', @openSearchServiceConfigEndpoint OUT, 'dataSources[i].openSearchServiceConfig.endpoint'
EXEC sp_OAMethod @jResp, 'StringOf', @RdsHttpEndpointConfigAwsRegion OUT, 'dataSources[i].relationalDatabaseConfig.rdsHttpEndpointConfig.awsRegion'
EXEC sp_OAMethod @jResp, 'StringOf', @AwsSecretStoreArn OUT, 'dataSources[i].relationalDatabaseConfig.rdsHttpEndpointConfig.awsSecretStoreArn'
EXEC sp_OAMethod @jResp, 'StringOf', @DatabaseName OUT, 'dataSources[i].relationalDatabaseConfig.rdsHttpEndpointConfig.databaseName'
EXEC sp_OAMethod @jResp, 'StringOf', @DbClusterIdentifier OUT, 'dataSources[i].relationalDatabaseConfig.rdsHttpEndpointConfig.dbClusterIdentifier'
EXEC sp_OAMethod @jResp, 'StringOf', @Schema OUT, 'dataSources[i].relationalDatabaseConfig.rdsHttpEndpointConfig.schema'
EXEC sp_OAMethod @jResp, 'StringOf', @RelationalDatabaseSourceType OUT, 'dataSources[i].relationalDatabaseConfig.relationalDatabaseSourceType'
EXEC sp_OAMethod @jResp, 'StringOf', @serviceRoleArn OUT, 'dataSources[i].serviceRoleArn'
EXEC sp_OAMethod @jResp, 'StringOf', @v_type OUT, 'dataSources[i].type'
SELECT @i = @i + 1
END
-- A sample JSON response body parsed by the above code:
-- {
-- "dataSources": [
-- {
-- "dataSourceArn": "string",
-- "description": "string",
-- "dynamodbConfig": {
-- "awsRegion": "string",
-- "deltaSyncConfig": {
-- "baseTableTTL": number,
-- "deltaSyncTableName": "string",
-- "deltaSyncTableTTL": number
-- },
-- "tableName": "string",
-- "useCallerCredentials": boolean,
-- "versioned": boolean
-- },
-- "elasticsearchConfig": {
-- "awsRegion": "string",
-- "endpoint": "string"
-- },
-- "httpConfig": {
-- "authorizationConfig": {
-- "authorizationType": "string",
-- "awsIamConfig": {
-- "signingRegion": "string",
-- "signingServiceName": "string"
-- }
-- },
-- "endpoint": "string"
-- },
-- "lambdaConfig": {
-- "lambdaFunctionArn": "string"
-- },
-- "name": "string",
-- "openSearchServiceConfig": {
-- "awsRegion": "string",
-- "endpoint": "string"
-- },
-- "relationalDatabaseConfig": {
-- "rdsHttpEndpointConfig": {
-- "awsRegion": "string",
-- "awsSecretStoreArn": "string",
-- "databaseName": "string",
-- "dbClusterIdentifier": "string",
-- "schema": "string"
-- },
-- "relationalDatabaseSourceType": "string"
-- },
-- "serviceRoleArn": "string",
-- "type": "string"
-- }
-- ],
-- "nextToken": "string"
-- }
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @authAws
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
END
GO