K2 5.4 On premise Rest API from SQL Server

  • 23 November 2021
  • 1 reply


I am trying to use the K2 Rest API from SQL Server. I have called other APIs in the past from this SQL server with success.

However whatever I try I am getting { "Message": "Authorization has been denied for this request." } as my Response text. And if I try actioning a task I get the same error.

e.g. here is some sample code:


DECLARE @URI NVARCHAR(MAX) = 'http://k2-dev/api/workflow/v1/tasks'
, @Object INT
, @ReturnCode INT
, @ResponseText VARCHAR(4096)

EXEC sp_OACreate 'MSXML2.ServerXMLHTTP', @Object OUTPUT
EXEC sp_OAMethod @Object, 'open', NULL, 'get', @URI, 'false'
EXEC @ReturnCode = sp_OAMethod @Object, 'send'
EXEC sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT
SELECT @ReturnCode, @ResponseText
EXEC sp_OAGetErrorInfo @object
EXEC sp_OADestroy @Object


Thinking this is something to do with not passing in credentials I also added the following lines (of course with a correct login and password) but still get the same error.


EXEC sp_OASetProperty @Object, 'Login', 'login'
EXEC sp_OASetProperty @Object, 'Password', 'password'
EXEC sp_OASetProperty @Object, 'BasicAuth', 1


I am able to successfully make the call using the Swagger page of the K2 Workflow API, both in reading tasks and actioning a task.

Any ideas on what I am doing wrong??

Thanks for any input... Dan Turner


1 reply

Userlevel 2
Badge +10

Hi surferdan1,


Out of curiosity, does it work with other GET methods (i.e. http://k2-dev/api/workflow/v1/workflows)? from SQL server? The error seems to indicate the authentication header is not setup correctly when calling K2 Rest API.