BookmarkSubscribeRSS Feed

Calling Decision Builder Services via REST

Started ‎05-24-2017 by
Modified ‎05-24-2017 by
Views 2,926

SAS Decision Builder brings SAS Decision Manager rule flows and predictive models together with conditional logic to build "Decision" services. For example, a Used Car Auction "Decision" might combine a car valuation model with an auto auction rule-flow to create a decision service that looks something like this:

 


Decision-Service-2.png

 

The idea being that a bid decision is governed differently for automatic versus manual transmission cars. For manual cars, the bid decision is generated using a predictive model (DecisionTree) and for automatics, the decision is generated by a rule flow (AutoRuleFlow).

 

Decision Service Deployment

Decision Builder services can be deployed for batch execution but, often, work best as real time services. For example, in the auction setting proposed above, you would need to rapidly generate new bid decisions as bidding escalates. When published for real-time, decisions are deployed to the SAS MicroAnalytic Service as modules. Deployment is performed in the Decision Builder Web Application simply by pushing the "Publish" button.

.

Decision Service Execution

MAS modules are meant to be integrated into web applications and can easily be called via REST (simple HTTP commands). I can approximate this scenario using curl. A curl command calling one of the deployed services would look like this:

 

 

This command is performing an HTTP POST method on the http://localhost/SASMicroAnalyticService/rest/modules/b45092bd-edd9-4c70-bea2-5bd725271fe6/steps/execute MAS module step using the local sasdemo user. The posted data comes from a local file, input.json which contains the following JSON. Each variable required for the conditional logic, predictive models, and rule flows must be included.

 

 

The response is directed to a file named output.json which, after successful completion, contains the following JSON. The response will contain all the variables returned by the decision service. Most notably here, the field, ISBADBUY = 0 so our bidder is free to bid:

 

.

Decision Service Discovery

In order to see what MAS modules are available along with their input and output message structure, simply query the MAS with the following REST GET query, http://localhost/SASMicroAnalyticService/rest/modules/. It can be issued in any web browser.

 

Modules-1024x288.png

 

When prototyping with test data, JSONLint or another JSON validator can help quickly format the returned JSON so it's easier to read.

 

jsonlint-300x291.png

 

Update: A few notes based on Comments I've received offline

This post was designed to convey understanding of Decision Builder services as quickly as possible. To that end it sacrificed best practices and security at the expense of brevity, convenience, and simplicity. However, if working with Decision Builder at a customer site, you should consider the following:

 

  1. Instead of putting credentials in the curl URL, use curl’s support for basic authentication such as curl --user sasdemo: Orion123 … or curl --netrc ## The credentials are in the .netrc file or _netrc
  2. All production deployments should access SAS’ REST APIs with TLS (https://)
  3. While JSONLint is handy for test data, avoid pasting real data into external JSON formatters. Another good way to format JSON is with PYthon: python –mjson.tool < output.json

.

Comments

Hi Stephen / Anna,

 

Thanks a lot for this article. I found it useful in validating my steps (for which I am using the HMEQ based tutorial provided in the Decision manager help centre).  I also referred the paper 

http://support.sas.com/resources/papers/proceedings17/SAS0606-2017.pdf alongside.

 

However, I did notice a couple of differences between this article and what I see on my installation.

 

i) I am able to publish my model successfully, however the URL I obtain is <server>/microanalyticScore/modules/evaluate_loans1_0,

 

not /SASMicroAnalyticsService/rest/modules

 

Is the below the correct URL to use? (I am on Viya 3.3)

 

 

image.png

 

ii) I guess this is a result of (i) , but while I am able to successfully call this through cURL (ie. with above URL), I still get my "output" containing ALL variables - even though I went to Decision manager and just checked BAD/REJECT/REVIEW as output variables I wanted returned. Is there any other way to make the "output.text return only specific variables ?

image.png

 

thanks and regards

Sundar

 

 

Version history
Last update:
‎05-24-2017 04:43 PM
Updated by:
Contributors

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Labels
Article Tags