We’re smarter together. Learn from this collection of community knowledge and add your expertise.

Calling Decision Builder Services via REST

by SAS Employee StephenFoerster on ‎05-24-2017 04:41 PM - edited on ‎05-24-2017 04:43 PM by Community Manager (758 Views)

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

.

Contributors
Your turn
Sign In!

Want to write an article? Sign in with your profile.