I want to see if I can import data to MSSQL from a REST call to a URL. I would like to reuse this code for an hypothetic stored procedure in the future. This just wants so be a proof of concept.
This URL has some JSON that I can use for my experiment:
http://api.plos.org/search?q=title:DNA
I check if the URL returns some JSON with Postman:
I now follow this guide that tells me how to structure the call and this is my code:
DECLARE @Object AS INT;
DECLARE @ResponseText AS nvarchar(max);
EXEC sp_OACreate 'MSXML2.XMLHTTP', @Object OUT;
EXEC sp_OAMethod @Object, 'open', NULL, 'GET','http://api.plos.org/search?q=title:DNA', 'false'
EXEC sp_OAMethod @Object, 'send'
EXEC sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT
SELECT @ResponseText
EXEC sp_OADestroy @Object
But unfortunately it returns me a NULL
column.
What am I doing wrong?
Is there anyone out there which has ever arrived to make a REST call through SSMS?