Calling external API within ScriptingRules
How to call an external API
Please, keep in mind all data (response and request body HAS to be a valid JSON object)
We do not support other formats, yet.
Calling an external API is done with http methods exposed on DR class in ScriptingRules. Usage is extremely simple. Supported methods are:
GET
POST
PUT
PATCH
DELETE
With syntax like this:
Options schema:
Error handling
Error handling can be with try {} catch (e) {}
syntax or without. In that case your solver execution will fail at error and that error will be displayed in output side of the testbench.
Example of try catch syntax with DecisonRules external API calls in ScriptingRules
Response object and how to work with it
Response object schema:
From every call of external API you will receive response schema that contains all the information you might need. Extracting data from schema is easy as it is JavaScript object, hence you can work with that normally. In the example below is ScriptingRule code that is outputting response status and response body.
Please note that output.status
and output.api_body
are both part of rules outputmodel
.
Functionality limitations
By default API calls are limited by these parameters:
maximum response size = 3000 bytes
maximum request body size = 10000 bytes
maximum possible redirects = 5
timeout = 2 seconds
All of these can be configured in docker version of DecisionRules to match your needs capabilities. Please refer to Environment Variables
Last updated