SQL Server
SQL Server
NetSuite OAuth1
See more OAuth1 Examples
Demonstrates adding OAUth1 authentication to a NetSuite REST API request.Chilkat SQL Server Downloads
-- 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
-- It requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @http int
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
EXEC sp_OASetProperty @http, 'OAuth1', 1
EXEC sp_OASetProperty @http, 'OAuthConsumerKey', 'CONSUMER_KEY'
EXEC sp_OASetProperty @http, 'OAuthConsumerSecret', 'CONSUMER_SECRET'
EXEC sp_OASetProperty @http, 'OAuthToken', 'ACCESS_TOKEN'
EXEC sp_OASetProperty @http, 'OAuthTokenSecret', 'TOKEN_SECRET'
EXEC sp_OASetProperty @http, 'OAuthRealm', 'ACCOUNT_ID'
EXEC sp_OASetProperty @http, 'OAuthSigMethod', 'HMAC-SHA256'
-- Not sure if this is needed for NetSuite requests.
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Cookie', 'NS_ROUTING_VERSION=LAGGING'
-- Replace ACCOUNT_ID with your actual account id, which is likely a 7-digit decimal number.
DECLARE @resp int
EXEC @hr = sp_OACreate 'Chilkat.HttpResponse', @resp OUT
EXEC sp_OAMethod @http, 'HttpNoBody', @success OUT, 'GET', 'https://ACCOUNT_ID.suitetalk.api.netsuite.com/services/rest/record/v1/salesOrder', @resp
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @resp
RETURN
END
EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
PRINT 'Response Status Code: ' + @iTmp0
PRINT 'Response Body:'
EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @resp
END
GO