Search code examples
resturlsas

How to call a SAS STP in background using proc http and http_tokenauth


I'm trying to call a stored process (STP) from SAS via proc http using the option background, to ensure that my main process does not wait for the STP to be finished. I do use the following code:

filename resp "<path to response file>";
%let url = https://<ServerName>:<port>/SASStoredProcess/do;
%let question_mark = ?;

proc http
url="%str(&url.)&question_mark.%nrstr(_action=background&_program=<path to STP>&num1=11&num2=22)"
out=resp
http_tokenauth;
HEADERS "Content-Type"="application/x-www-form-urlencoded" "Accept"="application/json";
quit;

Unfortunately, in my response file I do always receive the SAS logon page.

Sending username/pw as part of my URL does work, but it is not wanted for security reasons. Hence I need to use http_tokenauth, which works for non background STPs. Also, when I just paste my URL to the browser, it does work.

How can I ensure it does also work using proc http and http_tokenauth?

Additional Information:

Setup:

I do have a STP which is called by a process engine via REST and expects an immediate answer containing an ID.(Main STP) This main STP then needs to call a sub STP containing a process, which will approx. take one hour to be finished. Hence I do not want the Main STP to wait for the sub STP to be finished. Therefore the sub STP should be called in background.


Solution

  • Token authentication only works when using "do1" instead of "do". Referring to documentation: https://documentation.sas.com/?docsetId=stpug&docsetTarget=n0ax7wadghvldwn1bbarfuly6adl.htm&docsetVersion=9.4&locale=en

    Furthermore I'm using query to pass my parameters, which makes it more clear.

    So this does work now:

    %let url = https://<ServerName>:<port>/SASStoredProcess/do1;
    
    proc http 
      url="%str(&url.)"
      query=("_action"             = "background"
             "_program"            = "<path to STP>"
             "num1"                = "1"
             "num2"                = "2"
             )
      ct="application/x-www-form-urlencoded"
      http_tokenauth
      out=resp;
    quit;