Making REST Requests with the JavaScript API
Developers may need to get data from the Insight server that is not available from any JavaScript API methods by calling one of the Insight Server REST endpoints. The list of all the available REST endpoints is available online in the
REST API reference.
REST requests from a VDL or JS Insight view should be automatically include the authentication cookie in the request, as it will be within the same domain and session.
All REST resource URLs begin with /insightservices/rest/v1/data/. However the request may require a prefix on the url path if the Insight server is running in an environment where path-based routing is used. The JavaScript API provides a method (available since Xpress Insight 4.55.0) that automatically adds the necessary prefix to the REST endpoint URL if it is required.
The JavaScript method
insight.resolveRestEndpoint is documented in the JavaScript API Reference. Here is an example of making a REST request using the
resolveRestEndpoint method:
var appsUrl = insight.resolveRestEndpoint('/insightservices/rest/v1/data/project'); fetch(appsUrl).then(function (response) { return response.json(); }) .then(function (data) { var appNames = data.items.map(function(item) { return item.displayName; }); console.log(appNames); });