sql-serverweb-servicest-sql

Can you call a webservice from TSQL code?


Is there a way to call out from a TSQL stored procedure or function to a webservice?


Solution

  • Starting with SQL Server 2025, you can now call REST APIs directly from T-SQL using the new sp_invoke_external_rest_endpoint stored procedure. No need for sp_OACreate, CLR, or workarounds...

    DECLARE @response NVARCHAR(MAX);
    
    EXEC sp_invoke_external_rest_endpoint
        @url = 'https://jsonplaceholder.typicode.com/posts',
        @method = 'GET',
        @response = @response OUTPUT;
    
    SELECT @response AS Result;
    

    PS: It's disabled by default for security reasons and must be explicitly enabled:

    EXEC sp_configure 'external rest endpoint enabled', 1;
    RECONFIGURE WITH OVERRIDE;