Example of a REST Endpoint
You can use a REST endpoint to allow a client application to request details about a label template from Loftware Enterprise SP when used in conjunction with an appropriate business rule.
Note: See Controlling Access to System Settings for information about the access needed to view, create, modify, delete, or communicate with REST endpoints.

To support the REST endpoint in this example, a business rule is required. This business rule, named getDetailsRule, includes a Custom event trigger named getDetails that runs the following Run Data Map Script component block.
Tip: For information about creating a business rule, see Designing Business Rules with the Configurator.
Run Data Map Script Component Block
This script includes references to the data map entries (shown highlighted in this example) that the REST endpoint uses as a Request Key and a Response Key.
Script engine: Nashorn
var labelInfo = MAP.getStringValue("/labelName");
var document = Document.getDetail(labelInfo);
var docDetails = Utilities.stringify(document);
LOG.info("$$$$ - Document.getDetail - $$$$ getDetail: Got document:" + docDetails);
var lastError = API.getLastError();
var lastErrorStr = Utilities.stringify(lastError);
var result = "";
LOG.error("$$$$ - Document.getDetail - $$$$ errors, if any, otherwise undefined: " + lastErrorStr);
if (typeof lastErrorStr != 'undefined') {
result = lastErrorStr;
}
else {
result = docDetails;
}
MAP.putValue("/labelDetails", result);

The following are the properties for a REST endpoint named getDetailsEndpoint. When requested by a client application, this REST endpoint causes the getDetails event to occur. This event acts as a trigger to run the getDetailsRule business rule.
Data is saved to and retrieved from the data map by using the Request Key and Response Key, which are referenced by both the REST endpoint and the business rule. The Response Content Type specifies that the REST response returns JSON content. This means that the return values are arrays, so the business rule is responsible for configuring the format.
Property |
Value |
---|---|
Name |
getDetailsEndpoint |
Business Rule |
/Example/BusinessRules/getDetailsRule (Select the getDetailsRule business rule that you created. The actual path displayed should reflect the location in your Loftware Enterprise SP environment.) |
Business Rule Event |
getDetails |
Response Key |
/labelDetails |
Response Content Type |
application/json |
Request Method |
POST |
Request Key |
/labelName |
Character Encoding |
UTF-8 |
Description |
Post the details about a label template |

A client application can request the information from the REST endpoint via a URL. The URL may use either HTTP or HTTPS and it must include the IP address or domain name and the port that you use when signing into Loftware Enterprise SP. The port must be followed by the standard folder for REST endpoints (/spectrum-server/dynamic/), and then by the name of the REST endpoint.
For example, if the following is the URL that you use to sign into Loftware Enterprise SP
http://www.example.com:8080/loftwarespectrum
then the following is the URL that a requesting client application would use to communicate with Loftware Enterprise SP via the REST endpoint that you created.