sp_OAMethod to make rest api call

  • Greetings,

    I have a need to call a rest api against a resource. It a POST and would like to send the following as POST option

    http.post(url,

    '{

    "https": { rejectUnauthorized: settings.ssl },

    "headers": {

    "Authorization": "BASIC dfsdkfdsfyduyfiuhdfiuyu5y43=",

    "Content-Type": "application/json",

    "Accept": "application/json"

    }

    }'

    )

    Tried to this but it fails

    EXEC @ret = sp_OAMethod @token, 'open', NULL, 'POST', @url, 'false';

    EXEC @ret = sp_OAMethod @token, 'setRequestHeader', NULL, 'Authentication', @authHeader;

    EXEC @ret = sp_OAMethod @token, 'setRequestHeader', NULL, 'Content-type', @contentType;

    EXEC @ret = sp_OAMethod @token, 'setRequestHeader', NULL, 'https', '{"rejectUnauthorized":"false"}';

    EXEC @ret = sp_OAMethod @token, 'send', NULL, null;

  • Thanks for posting your issue and hopefully someone will answer soon.

    This is an automated bump to increase visibility of your question.

  • You could probably add some more details, like what's exactly failing etc.

    According to https://stackoverflow.com/questions/24118508/how-can-i-pass-a-body-from-stored-procedure-to-a-rest-service/38185814 it should be possible so you probably messed up the call

  • Can someone help.... i am getting a null response. if you pass the actual URL u do get a JSON back. Waht am i doing so wrong.....the HTTP gods are going against me!

    Declare @Object as Int;

    Declare @ResponseText as Varchar(8000);

    Declare @Body as varchar(8000) =

    '{

    "Subsystem": 1,

    "Exception": "",

    "Message": "I have done what you asked",

    "Time": "2014-06-09T11:16:35",

    "Attribute": { "Number of attempts": "0" }

    }'

    Exec sp_OACreate 'MSXML2.ServerXMLHTTP', @Object OUT;

    EXEC sp_OAMethod @Object, 'open', NULL, 'get','https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=pubmed&id=32277993', 'false'

    Exec sp_OAMethod @Object, 'setRequestHeader', null, 'Content-Type', 'application/json'

    Exec sp_OAMethod @Object, 'send', null, @body

    Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT

    Select @ResponseText

    Exec sp_OADestroy @Object


    Kind Regards,

    Sandeep Kataria

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply