LogoLogo
API Documentation
Version 1.19.5 and Older
Version 1.19.5 and Older
  • DecisionRules Documentation
  • API
    • API Introduction
    • API Keys
      • Solver API Keys
      • Management API keys
      • BI API keys
    • Rule Solver API
    • Management API
      • Deprecated Endpoints
    • Console Logs API
    • Business Intelligence API
      • Deprecated Endpoints
    • Datacenters & Locations
      • Global Cloud
      • Regional Cloud
    • Apache Kafka Solver API
    • Endpoint Settings
    • Archive
      • Rule Flow Solver API (DEPRECATED)
  • Decision tables
    • Decision Tables Introduction
    • Table Designer
    • Input & Output JSON Model
      • Simple Editor
      • JSON Editor
      • Binding to Model
    • Supported Data Types
    • Operators and Functions
      • Basic operators
      • Date operators
      • Functions
        • Logical Functions
        • Math Functions
        • Date and Time Functions
        • Text Functions
        • Data Functions
        • Array Functions
        • Integration functions
        • Functions and JSON
    • Export & Import of Decision Tables
      • Export Decision Table
      • Import Decision Table
      • File Structure of JSON Format
      • Managing Decision Table in Excel/Google Sheets
      • Deprecated Formats: XLSX v.1 and CSV
    • Table Operations
      • Filter Values
      • Valid Values
      • Sorting
  • Decision Trees
    • Decision Trees Introduction
    • Decision Tree Designer
    • Export & Import Decision Trees
      • Export Decision Tree
      • Import Decision Tree
  • Scripting Rules
    • Scripting Rule Introduction
    • Custom functions in Scripting Rules
    • Calling external API within ScriptingRules
    • Use Rule Variables in Scripting Rules
    • Call Embedded Rules in Scripting Rules
    • Export & Import Scripting Rules
      • Export Scripting Rule
      • Import Scripting Rule
    • Tips
  • Rule Flow
    • Rule Flow Designer
    • Rule Flow Mapping
    • Rule States in Rule Flow
    • Warnings & Errors
    • Rule Flow Limits
    • Export & Import Rule Flows
      • Export Rule Flow
      • Import Rule Flow
  • Workflow
    • Workflow Introduction
    • Workflow Designer
    • Workflow Nodes Overview
    • Workflow Limits
  • Other
    • Rule Alias
    • Execution Strategy
    • Rule State
    • Rule Versioning
    • Favorite Rules
    • Rule Variables
    • Rule Comparison
      • Decision Table Comparison
      • Decision Tree Comparison
      • Scripting Rule Comparison
    • Rule Tags
    • Rule Dependencies
    • Test Bench
    • Single Sign-On (SSO)
    • Event timeline
    • Rule Lock
    • Rule Migration Strategies
    • Changes in Version 1.19.0 (10/2024)
  • Organizations
    • Introduction
      • Access to Organization
    • Structure
      • Organization Roles
      • Members
      • Teams
      • Spaces
      • Space Roles
      • Policies
      • Settings
  • Teamwork
    • Dashboard
    • Folders
    • Spaces
    • Manage Spaces
    • Share Rules Between Spaces
    • Users & Roles
    • Teamwork Indicator
  • SDK and Integrations
    • Languages / Frameworks
      • SQL Server
      • Oracle PL/SQL
      • PostgreSQL
      • JavaScript
      • Java Spring Example
      • PHP Library
      • Python Library
      • .NET Library
      • Google Tag Manager
    • Excel Add-in
  • Business Intelligence
    • Audit Logs
    • Create a Power BI Report
    • Connect Power BI to Business Intelligence API
    • Connecting from Power BI (deprecated)
    • Connect DecisionRules to Power BI Using Our Custom Connector
  • Billing
    • Invoices & Billing
    • Change Product Plan
    • Billing Information
    • Plan Limits Explained
  • Regional Cloud
    • Regional Cloud
    • Region Specific API URLs
  • On-Premise / Docker
    • Environment Variables
    • Redis Connection Modes
    • Setup Single Sign-On (SSO)
      • Set up Microsoft Entra ID SSO
      • Set up Google SSO
    • DecisionRules Application
      • Minimal Requirements
      • DecisionRules Server
      • DecisionRules Client
      • DecisionRules Business Intelligence
      • Networking Between Docker Containers
    • Docker Showcase App
      • Showcase
      • Showcase + Business Intelligence
    • AWS Setup
      • AWS ECS/Fargate
      • Cache - Amazon ElastiCache
    • Microsoft Azure Setup
      • Database - Azure CosmosDB
      • Cache - Azure Cache for Redis
      • Azure Container Apps
    • Azure Red Hat OpenShift
    • Google Kubernetes Engine (GKE)
    • Kubernetes Setup
      • Kubernetes Setup with Business Intelligence
    • Logging options
    • CD/CI Pipelines
      • Azure DevOps CICD Pipelines
      • Using Migration script (old way)
    • Offline License
  • Terms & Conditions
    • Terms and Conditions
    • Privacy Policy
    • Service Level Agreement
      • Community Support
      • Standard Cloud (SaaS)
      • Silver SLA
      • Gold SLA
      • Custom SLA
    • Sub-Processor List
  • Roadmap 🚲 🗺️
  • Release Notes
    • Public Cloud
    • On-Premise / Private Cloud
Powered by GitBook
On this page
  • How to call an external API
  • Error handling
  • Response object and how to work with it
  • Functionality limitations

Was this helpful?

  1. Scripting Rules

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:

const getMethod = DR.http.get(<URL>, [OPTIONS]);
const postMethod = DR.http.post(<URL>, <DATA>, [OPTIONS]);
const putMethod = DR.http.put(<URL>, <DATA>, [OPTIONS]);
const patchMethod = DR.http.patch(<URL>, <DATA>, [OPTIONS]);
const deleteMethod = DR.http.delete(<URL>, [OPTIONS]);

Options schema:

{
    "headers": {} //custom headers like key:value pair
}

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

try {
    const result = DR.http.get("myapiurl.com");
    
    output.resultValue = result.body;
} catch (e) {

    output.errorValue = e;
}

Response object and how to work with it

Response object schema:

{
    status: 200, // HTTP response status codes
    body: {}, // Response body
    config: {
        contacted_url: "myapi.com", // Called URL
        request_headers: {} // Request headers
    },
    response_headers: {}, // Response headers
    timestamp: 1661760778584 // Time of call as timestamp
}

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.


try {

    const options = {
        headers: {
            "X-Name": "Joe",
            "X-Key": "12345XXXX"
        }
    }

    const response = DR.http.get("https://api.myapi.io", options);

    output.status = response.status;
    output.api_body = response.body;
} catch (e) {
    output.Error = e;
}

return output;

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

Was this helpful?