Skip to main content

 none
How Send POST Request with Authorization key using stored procedure RRS feed

  • Question

  • ALTER procedure [AVTRA].[export_order_from_local_to_server]
    as
    -- Variable declaration
    DECLARE @authHeader NVARCHAR(64);
    DECLARE @contentType NVARCHAR(64);
    DECLARE @postData NVARCHAR(2000);
    DECLARE @responseText NVARCHAR(2000);
    DECLARE @responseXML NVARCHAR(2000);
    DECLARE @ret INT;
    DECLARE @body NVARCHAR(max);
    DECLARE @status NVARCHAR(32);
    DECLARE @statusText NVARCHAR(32);
    DECLARE @token INT;
    DECLARE @url NVARCHAR(256);
    -- Set Authentications

    SET @authHeader = 'bearer rGVU9eegEK-CrahyVOMi53_Wai6b6TXFg78vi0jHZ53HzRGZL-3lqEkP2vmny6XJE4uqbSM96BTXQ6miBfQ7OOtEuG0pMO6VcwMW_FNGPQskSMbivdrBFJ0VdzTwBpMl-I1dobw8pL1qRqujsIpMUCSR-jWcu8DIwl-UWr0fEHfQJgWd8vbWYF-8P09Ob-sYwIx9wjkpWQiRsToiwMWGeGK2-VG1rn7_bkvg7-sxtHSnBtbBR4Gq4oKqAnkHAdeSb7JeEPaGbX9hrNskzlPIJ8TVPjL0YUoiU5ndDppGdPlRPLEgXRz604nbvsw_FDopZ-qjRfX8dFWqbkTleui-7A';
    SET @contentType = 'application/json';
    SET @body='{"WHSEID":"ENTERPRISE","BUSINESSUNITID":"1","ITEM":[{"SKU":"00068900001","DESCR":"Test Item Descr","PRICE":"1","BRAND":"1","PRODUCTLINE":"1","PRODUCTTYPE":"1","STDNETWGT":"55.23","SKUGROUP":"","ABC_CLASS":"B","CLASS":"15","ACTIVE":"YES"}]}';
    -- Set your desired url where you want to fire request
    SET @url = 'rel="noopener">http://localhost/BOATAPI/api/ISKUMST/IMPORTISKUMST/'
    -- Open a connection
    EXEC @ret = sp_OACreate 'MSXML2.ServerXMLHTTP', @token OUT;
    IF @ret <> 0 RAISERROR('Unable to open HTTP connection.', 10, 1);
    -- make a request
    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,'setRequestBody',@body;
    EXEC @ret = sp_OAMethod @token, 'send'
    EXEC @ret=sp_OAMethod @token , 'FullRequestString',@body OUT, 'POST';
    --EXEC @ret=sp_OAGetProperty @token, 'LastMethodSuccess', @iTmp0 OUT
    -- Handle responce
    EXEC @ret = sp_OAGetProperty @token, 'status', @status OUT;
    EXEC @ret = sp_OAGetProperty @token, 'statusText', @statusText OUT;
    EXEC @ret = sp_OAGetProperty @token, 'responseText', @responseText OUT;
    -- Print responec
    PRINT 'Status: ' + @status + ' (' + @statusText + ')';
    PRINT 'Response text: ' + @responseText
    • Moved by ArthurZ Wednesday, September 11, 2019 1:17 PM Not SSIS related
    Wednesday, September 11, 2019 9:31 AM

All replies

  • Hi 

    I've gone through your code and matched with this code example, it seems correct.  

    so what issue did you met? 

    Sabrina 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, September 12, 2019 6:04 AM
  • Hi,

    Check if the following link help you:
    https://www.example-code.com/sql/http_authentication.asp


    signature   Ronen Ariely
     [Personal Site]    [Blog]    [Facebook]    [Linkedin]

    Saturday, September 14, 2019 12:38 AM
    Moderator
  • Hi Friend

     

    I am writing to follow up this thread with you. Have you solved your issue? If you have solved your issue ,in order to close this thread, please kindly mark helpful replies as answers or share your methods with us. By doing so, it will benefit all community members who are having this similar issue.  Your contribution is highly appreciated.

     

    Regards,

    Sabrina


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, September 17, 2019 6:50 AM