Using CURL with SAS Stored Processes

I’ve said it before and I’ll say it again - SAS is an unparalleled platform for lightning fast development of enterprise-grade, business focused web applications.  Not least because it comes pre-installed with a Web Server and an incredibly powerful Application Server for building the backend services - known as Stored Processes.

In order to build robust, scalable Stored Process Web Applications it’s imperative to be able to test these services in an automated fashion - eg from your test server or local machine, using a test framework like jenkins or directly with shell scripts.  If you have IWA / SSO configured in SAS then this is straightforward - simply call the URL.  However if you are connecting to a machine outside your intranet, or if passwords are required for some other reason, then the following code snippet will be helpful.

curl -v -L -c cookiefile -b cookiefile \
    -d "_program=$STP&_username=$USERNAME&_password=$PASSWORD" \
    https://yourdomain.com/SASStoredProcess/do

Things to note:

  1. A cookiefile is used so that the session token can be written (-c) and subsequently read (-b) by the SASLogon redirect.
  2. The _username and _password parameters are used to authenticate (see docs)
  3. -v for verbose logging, -L to tell curl to follow the redirect (SASLogon) location
You can of course redirect the output to a file, by appending > filename.ext or using the --output option.

If you’d like more info on building web applications on SAS, check out these 5 tips and this quick start guide, or the SPWA tag on https://sasensei.com and last but not least, https://sasjs.io.