Sample code for 30+ languages & platforms
SQL Server

BrickLink OAuth1 using Chilkat REST

See more BrickLink Examples

Demonstrates sending an api.bricklink.com request with OAuth1 authentication using Chilkat REST.

Note: This example requires Chilkat v9.5.0.91 or greater (due to adjustments made within Chilkat to support bricklink OAuth1 needs).

Chilkat SQL Server Downloads

SQL Server
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

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

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

    EXEC sp_OASetProperty @oauth1, 'ConsumerKey', 'Your Consumer Key'
    EXEC sp_OASetProperty @oauth1, 'ConsumerSecret', 'Your Consumer Secret'
    EXEC sp_OASetProperty @oauth1, 'Token', 'Your OAuth1 Token'
    EXEC sp_OASetProperty @oauth1, 'TokenSecret', 'Your Token Secret'
    EXEC sp_OASetProperty @oauth1, 'SignatureMethod', 'HMAC-SHA1'

    DECLARE @rest int
    EXEC @hr = sp_OACreate 'Chilkat.Rest', @rest OUT

    EXEC sp_OAMethod @rest, 'SetAuthOAuth1', @success OUT, @oauth1, 0

    EXEC sp_OAMethod @rest, 'Connect', @success OUT, 'api.bricklink.com', 443, 1, 1
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @oauth1
        EXEC @hr = sp_OADestroy @rest
        RETURN
      END

    DECLARE @sbResponse int
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponse OUT

    EXEC sp_OAMethod @rest, 'FullRequestNoBodySb', @success OUT, 'GET', '/api/store/v1/orders?direction=in', @sbResponse
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @oauth1
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @sbResponse
        RETURN
      END


    EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @iTmp0 OUT
    PRINT 'Response status code = ' + @iTmp0

    DECLARE @json int
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'LoadSb', @success OUT, @sbResponse
    EXEC sp_OASetProperty @json, 'EmitCompact', 0
    EXEC sp_OAMethod @json, 'Emit', @sTmp0 OUT
    PRINT @sTmp0

    EXEC @hr = sp_OADestroy @oauth1
    EXEC @hr = sp_OADestroy @rest
    EXEC @hr = sp_OADestroy @sbResponse
    EXEC @hr = sp_OADestroy @json


END
GO