About the RASON REST API

The RASON REST API provides a set of simple, easy to use endpoints for defining models, solving them using conventional optimization, Monte Carlo simulation, stochastic optimization or data mining/forecasting methods and getting results in JSON. A great way to see the REST API in action is to use our Editor page -- select an example model or enter/edit your own, then click the Create App link to generate a Web page, complete with your model, JavaScript/JQuery code to solve it via AJAX calls to the REST API, and some sample HTML markup.

How to Use the API

For small, simple models (including all the examples on the Editor page) that can be solved in limited memory within 30 seconds of CPU time, you can run an optimization, simulation, data mining/ forecasting method or calculate a decision table and get results with a single API call: POST rason.net/api/solve. To keep your application response time acceptable to your user, you should use this endpoint judiciously.

For larger models that require more time or memory, you can use separate API calls to (i) upload your model plus data files, creating a named model resource on the RASON server, (ii) start an optimization, simulation, data mining or decision table model running, (iii) check on its status and get progress information, and finally (iv) retrieve results when the solution process is complete. If necessary, you can stop a long run in progress with an API call. Afterwards you should delete the model.

Other API calls allow you to diagnose a model to determine its type (linear, quadratic, nonlinear, stochastic, etc.) and size before solving it (mostly useful in model design and development), retrieve a model resource that you've previously created (including the full text of the model), update the model text of an existing model resource, get a list of all the model resources you've created, and delete a model resource.

Authorization Headers

Every RASON REST API call must include an 'Authorization' header with value 'Bearer ' followed by your account OAuth token, which you can copy and paste from the My Account page. If you use the "Create App" facility on the Editor page, the JavaScript code generated to run your model will include your Authorization header and OAuth token -- it really is a complete application that you can just open and run!

Model Resources and Location Headers

When you create a model resource with POST rason.net/api/model, the response will include a 'Location' header whose value is the model name or id below, and in the API summary on the Editor page. You can retrieve this header in an AJAX response handler function with jqXHR.getResponseHeader('location') -- see the "Create App" JavaScript code for an example. When you make an API call that requires a model name or id, you simply substitute the string you get from within the Location header for nameorid.

It is your responsibility to delete model resources when you no longer need them. This is easy to do: just use the API call DELETE rason.net/api/model/nameorid. The "Create App" JavaScript code shows you how to make this call. Deleting a model resource also removes any data files that were uploaded when it was created.

Responses: Solution Status and Results

The RASON Server response to every API call is in JSON. The best way to see how to handle the response in your application is to examine the "Create App" JavaScript code, and use the Editor page to see the actual response when you solve your own model.

When you call GET rason.net/api/model/nameorid/status to check the solution status, the JSON response format is fixed, and easy to examine. For example, if the solution process has completed, you'll get { "status": "Complete" }, so you can check for this with code such as if (response.status == "Complete"). When you call GET rason.net/api/model/nameorid/result to retrieve results, the response includes a fixed portion describing the solution status, and a variable portion that depends on what you ask for in the RASON model.

For example, if you run the example model AirlineHub.json (available in the dropdown list on the Editor page), you'll see the following response:

{
    "status": {
        "code": 0,
        "id": "2590+AirlineHubExample+2021-09-15-20-44-08-732107",
        "codeText": "Solver found a solution.  All constraints and optimality conditions are satisfied."
    },
    "variables": {
        "x": {
            "finalValue": 1.25004
        },
        "y": {
            "finalValue": 4.00001
        },
        "z": {
            "finalValue": 2.136
        }
    },
    "objective": {
        "obj": {
            "finalValue": 2.136
        }
    }
}
   

The fixed part of the response includes the "status" property, which tells you the outcome of the optimization. You can test this with JavaScript code such as if (response.status.code == 0). The variable part of the response includes final values for the three decision variables x, y and z, and the objective being minimized (which is the third variable, z). We got this part of the response because we asked for it in the RASON model -- we included the property finalValue: [] in the definition of the objective and each decision variable.

To retrieve the final value of the objective in your JavaScript code, you would simply reference response.objective.obj.finalValue. If the model had asked for the dual value of x by including the property dualValue: [], your JavaScript code could obtain this value with a reference response.variables.x.dualValue.

Complete List of API Calls

Here is a complete list of RASON REST API calls. You can exercise these calls on the Editor page.

POST rason.net/api/diagnoseDiagnose the model in the payload and return its type and size.
POST rason.net/api/optimizeOptimize the model in the payload and immediately return the results.
POST rason.net/api/simulateRun the simulation model in the payload and immediately return the results.
POST rason.net/api/datamineRun the datamining model in the payload and immediately return the results.
POST rason.net/api/decisionRun the decision model in the payload and immediately return the results.
POST rason.net/api/solveRun the model (any type) in the payload and immediately return the results with a OData endpoint.
POST rason.net/api/scoreScores given the fitted PMML/JSON model and new data attached to the request as "form-data".
POST rason.net/api/modelCreate a model resource containing the payload and return the model resource id.
POST rason.net/api/model/nameCreate a named model resource containing the payload and return the model resource id.
GET rason.net/api/modelGet a list of all the model resources for my account and return them as a single JSON array.
GET rason.net/api/model/name/championGets a list of all the model resources for the champion versions of name for my account and return them as a single JSON array.
GET rason.net/api/model/nameoridReturns model text for the champion or most recent model or workbook for name or the specific model resource for id.
POST rason.net/api/model/nameorid/fitted-infoSends the fitted model contained within the request body to the RASON server and returns a response.
GET rason.net/api/model/nameorid/fitted-infoReturns the name of the fitted model, the format of the fitted model, the model type, the algorithm used to fit the model, the included features and the output variable.
GET rason.net/api/model/nameorid/runtokenGets a runtime token for a named (or unnamed) model.
PUT rason.net/api/model/nameoridUpdates the previously posted named or unnamed model using the resource ID to contain the payload model text.
PATCH rason.net/api/model/nameoridWith "champion" in the body, marks the model as the current champion.
POST rason.net/api/model/nameorid/optimizeCreates a new instance of the model and starts an optimization of the model in the resource nameorid.
POST rason.net/api/model/nameorid/simulateCreates a new instance of the model and starts a Monte Carlo simulation of the model in the resource nameorid.
POST rason.net/api/model/nameorid/datamineCreates a new instance of the model and starts a data mining task in the resource nameorid.
POST rason.net/api/model/nameorid/decisionCreates a new instance of the model and starts a calculation of the decision table model in the resource nameorid.
POST rason.net/api/model/nameorid/diagnoseCreates a new instance of the model and starts a diagnosis of the model in the resource nameorid.
POST rason.net/api/model/nameorid/solveCreates a new instance of the model, starts a solve (of any problem type) in the resource nameorid and automatically creates an OData endpoint.
POST rason.net/api/model/nameorid/scoreScores a fitted PMML/JSON model POSTed to the RASON server given the new data attached to the request.
GET rason.net/api/model/nameorid/optimizeStart an optimization of the model in the resource nameorid.
GET rason.net/api/model/nameorid/simulateStart a Monte Carlo simulation of the model in the resource nameorid.
GET rason.net/api/model/nameorid/datamineStart a data mining task in the resource nameorid.
GET rason.net/api/model/nameorid/decisionStart a decision table calculation in the resource nameorid.
GET rason.net/api/model/nameorid/diagnoseStart a model diagnosis in the resource nameorid.
GET rason.net/api/model/nameorid/solveAccepts an analytic model (optimization, simulation, data mining or decision table) in JSON and places it in the queue to be solved.
GET rason.net/api/model/nameorid/statusGet the status of the last optimization/simulation run for resource nameorid.
GET rason.net/api/model/nameorid/resultGet results from the last optimization/simulation run for resource nameorid.
GET rason.net/api/model/nameorid/result/dataDownload results to an external data file for nameorid.
POST rason.net/api/interfaceGenerates an interface for a reusable RASON model (RASON script or Excel workbook) that can be utilized in a decision flow.
GET rason.net/api/interfaceGenerates an interface from a model saved to a OneDrive or Sharepoint account, that can be utilized in a decision flow.
GET rason.net/api/model/interfaceGenerates an interface from an already posted reusable RASON model, that can be utilized in a decision flow.
POST rason.net/api/model/excelGenerates a single-stage decision flow with a stage invoking the reusable Excel model that is located on the user's OneDrive or SharePoint account using the named connection created on the user’s www.rason.com account.
POST rason.net/api/scoring-modelGenerates the script for the RASON Scoring stage by parsing the named fitted model residing on the RASON server or in a OneDrive account or SQL Server.
GET rason.net/api/model/nameorid/scoring-modelGenerates the script for the RASON Scoring stage by parsing the named fitted model residing on the RASON server or in a OneDrive account or SQL Server.
POST rason.net/api/stagesPOSTs a list of stages in a decision flow.
GET rason.net/api/model/nameorid/stagesGet a list of stages from a previously posted decision flow.
POST rason.net/api/stages/{stage}POSTs a specific {stage} in a decision flow.
GET rason.net/api/model/nameorid/stages/{stage}Returns information about the specified {stage}.
GET rason.net/odata/odatalogReturns a log of odata requests for the requesting user.
GET rason.net/odata/resultReturns the results, in OData format, from a model previously solved with POST rason.net/api/model/id/solve.
GET rason.net/odata/resultsReturns RASON models on a user’s account with persistent results and composes the OData feed with basic model info.
GET rason.net/odata/solvelogReturns the log of solve requests for the requesting user.
POST rason.net/api/flowGenerates and returns the flow in the response for the Excel/RASON model attached in the body of the request.
GET rason.net/api/flowReturns the flow in the response for the model on a OneDrive or SharePoint account or for the model attached in the body of the request.
POST rason.net/api/model/nameorid/flowGenerates and posts the decision flow for the RASON or Excel model on the user's account.
GET rason.net/api/model/nameorid/flowReturns the generated flow for the RASON or Excel model posted on the user's account.
PUT rason.net/api/model/nameorid/flowGenerates and modifies the decision flow for the RASON or Excel model posted on the user's account.
POST rason.net/api/model/flowGenerates and publishes the single-stage flow invoking a RASON/Excel model stored on the user's OneDrive/SharePoint account.
GET rason.net/api/model/flowReturns the single-stage flow invoking a RASON/Excel model stored on the user's OneDrive/SharePoint account.
PUT rason.net/api/model/flowGenerates and modifies the single-stage flow invoking a RASON/Excel model stored on the user's OneDrive/SharePoint account.
POST rason.net/api/model/nameorid/stopStop the RASON model running for resource nameorid, discard results.
POST rason.net/api/model/nameorid/stop/scheduleStops a run for the model instance, all future runs and removes the schedule
PUT rason.net/api/model/ExcelUpdates a previously posted single-stage decision flow POSTed using POST rason.net/api/model/excel?connection-name=.
DELETE rason.net/api/model/nameoridDelete the model resource id and any associated data files.
DELETE rason.net/api/model/nameorid/runtokenDeletes a run time token for a named (or unnamed) model.