I am trying to get data from a webservice in to a Json_table variable so i can process it later. I try to follow and reproduce the code in tutorial https://www.youtube.com/watch?v=93q8joTcRpQ and try it with another url (see code below). I expect a response in the result grid but instead the error is raised that there is no object created.
I also reconfigured the sql server as was suggested:
EXEC sp_configure 'show advanced options', 1
RECONFIGURE
GO
EXEC sp_configure 'Ole Automation Procedures', 1
RECONFIGURE
GO
The code what i use for getting the data is:
declare @token int
, @ret int
, @url nvarchar(max)
, @authheader nvarchar(64)
, @contenttype nvarchar(64)
, @apikey nvarchar(32)
declare @json AS TABLE(Json_Table NVARCHAR(MAX))
-- URL to webservice
SET @url = 'https://opendata.cbs.nl/ODataApi/OData/80477ned/PlaatsEnGemeentenamen'
-- Create new instance to of webrequest
--EXEC @ret = sp_OACreate 'MSXML2.XMLHTTP', @token, OUT;
EXEC @ret = sp_OACreate 'MSXML2.ServerXMLHTTP', @token, OUT;
IF @ret <> 0 RAISERROR('Unable to open http Connnection', 10 , 1)
-- Open connnection and send request with get method
EXEC @ret = sp_OAMethod @token, 'open', null, 'GET', @url, 'false';
EXEC @ret = sp_OAMethod @token, 'send'
-- insert response into JSON tablevariable
INSERT INTO @json (Json_Table) EXEC sp_OAGetProperty @token, 'ResponseText'
-- grap jsson string from jsontablevariable
select * from @json
I really appreciate the help !! Manny thanks
Erik