Datasources
Last updated
Last updated
If you have data available from a RESTful API then you can configure the datasource feature to request this data when a query is made.
Using a datasource has several advantages:
it ensures the data is the most up-to-date
it reduces the questions the reasoning engine might ask
it only makes the request if necessary, therefore if it's a pay-per-use API it can limit costs
it requires less technical effort compared to injecting data
Before you begin, make sure you have API access and reviewed the API documentation for your chosen datasource. Ensure you have details of the endpoints, authentication methods, request parameters and response formats. Setting up a datasource involves the following tasks:
To add a datasource, click on the canvas and select Add Datasource
, give is a friendly name and select the subject of the datasource.
A user-friendly name can be provided for the datasource to make it clearer on the graph. This is optional, if a name is not provided the datasource URL will be used instead.
A datasource must be linked to the subject of the request. e.g. if the request is about a vehicle, the vehicle reg concept might be selected. If it's about an employee, an employee concept might be selected.
A datasource can only be linked to a concept that is the subject of a relationship. Concepts that are only the object of a relationship will not be available to select in the dropdown.
If you need the data from this concept for the request (e.g. vehicle reg), you can represent it in the request as a variable {{%S}}.
If the request requires additional dynamic information from the knowledge map, this can be configured by setting up additional input variables.
This allows you to tell the datasource where in the knowledge map the data you need is located, by selecting the appropriate relationship.
For example, you may also need to provide a date range as a request parameter that must be dynamic per request. Expanding the Input Variables section and selecting the relationships that will contain the start date and end date provides a method for getting this data at runtime. This data can then be used in the request by enclosing the variable in double curly braces e.g. {{%START_DATE}}
Once you have setup your datasource to obtain all the data required for the request, you can now configure the request itself.
Consult the API documentation to ensure you are aware of the API endpoints, request parameters, authorisation and headers.
Configure the method, hostname and path for your datasource request.
The methods supported include GET (default) and POST.
To use variables within the request, ensure they are enclosed in double-curly braces e.g. {{%VARIABLE}}
If required for your datasource, CDATA can be provided with the request. Consult your API documentation to determine if this is a requirement.
If required for your datasource, configure the necessary headers. Variables can be used as header values.
The purpose of a datasource is to generate facts from this external source, which the reasoning engine can use to make decisions.
However, the data needs to be mapped from the API response (most likely a JSON structure) into the structure required by your knowledge map (subject>relationship>object). This is where the mapping from JSON to your knowledge map is configured.
From the Output facts
section you can select the relationships you want to create facts for. Facts can only be created for relationships that share the same subject as the datasource, therefore the dropdown will only display applicable relationships. The subject is disabled, as values from the API response can only be applied to the object.
In the object field, you need to configure the path to the value you require from the API response. This uses a JSON path utility to navigate and filter the response to obtain the value you need for the object in question.
To learn how to use datasources with some practical examples, head over to the Academy.