I have a webserver running a REST API, and I need to query from a SQL Server.
I can easily make the API work with Postman and the NTLM option as seen below:
but I have no idea how to do that with SQL code. I have been using HTTP:
Declare @Object as Int;
DECLARE @hr int
Declare @json as table(RESPONSE nvarchar(max))
Exec @hr=sp_OACreate 'WinHttp.WinHttpRequest.5.1', @Object OUT;
EXEC @hr= sp_OASetProperty @Object, 'Option', '13056', 4
--EXEC @hr = sp_OASetProperty @object, 'WinHttpRequestOption_SslErrorFlag_Ignore_All', 1;
IF @hr <> 0 EXEC sp_OAGetErrorInfo @Object
Exec @hr=sp_OAMethod @Object, 'open', NULL, 'get',
'https://blahblahblah/GetInventoryDetails?barcode=00387127399232474375',
'false'
--IF @hr <> 0 EXEC sp_OAGetErrorInfo @Object
Exec @hr=sp_OAMethod @Object, 'send'
--IF @hr <> 0 EXEC sp_OAGetErrorInfo @Object
Exec @hr=sp_OAMethod @Object, 'responseText', @json OUTPUT
--IF @hr <> 0 EXEC sp_OAGetErrorInfo @Object
INSERT into @json (RESPONSE) exec sp_OAGetProperty @Object, 'responseText'
-- select the JSON string
select * from @json
EXEC sp_OADestroy @Object
But this obviously returns a 401 unauthorized.
Any way to achieve that?