Having followed a fantastic answer found here: Parse JSON from web in SQL Server 2017
I was able to get the response body from the HTTP request to an REST API server which responds in JSON format. This works beautifully when the API endpoint doesn't require a session ID.
However the endpoint I would like to query requires a session ID (which I have tested a permanent ID without any problems with authentication).
When analyzing the HTTP request in Wireshark I can see that there is no mention of my header within the data packet. But looking at when I interface with the API via a web browser I can see my Session-Id being passed.
Here is my SQL:
Declare @Object as Int;
Declare @Response table (txt nvarchar(max));
Exec sp_OACreate 'MSXML2.serverXMLHTTP', @Object OUT;
Exec sp_OAMethod @Object, 'open', NULL, 'GET',
'http://someip/Rest/EndPoint'
Exec sp_OAMethod @Object, 'setRequestHeader',null,'Session-Id','123456789'
Exec sp_OAMethod @Object, 'send'
Insert Into @Response (txt)
Exec sp_OAMethod @Object, 'responseText'
Exec sp_OADestroy @Object
Select txt From @Response
I can achieve this simply in Javascipt (see below) without trouble; but need it in SQL to parse the response into an SQL table without using a middle man like NodeJS and sending the response to SQL server.
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.setRequestHeader("Session-Id", "123456789");
Any/all help would be much appreciated!
Thanks