Create JavaScript Resource Types

You can create JavaScript Resource Types for full control over returned JSON as shown here.

In this example, we are retrieving Resource information from another Rest Server (line 2) as the data for the OrdersSvc Sub Resource.

This enables you to deliver JSON results combining managed data (here, Customers) with external service results (OrdersSvc).

The actual code:

var url = req.baseUrl;// e.g.
url = url.replace("sample","demo");// compute baseURL of target system
url = url + "v1/PurchaseOrders";// add version/endPoint
var key =;// containingRow is system supplied
log.debug("..using key: " + key + ", and url: " + url);
key = key.replace(/'/g, "''");
var params= {
   filter: "customer_name='" + key + "'"
//special apikey in this project to allow access from url (?auth=demo_full:1)
var settings = {
   headers: {
      Authorization: "CALiveAPICreator demo_full:1"
//////////// Built in utility to make REST GET call
var response =  SysUtility.restGet(url, params, settings);
return JSON.parse(response);


The system inserts your returned JSON (OrdersRest) into the larger result, as shown below:

    "name": "Alpha and Sons",
    "balance": 4484,
    "@metadata": {
      "href": "http://localhost:8080/APIServer/rest/el-local/demo/v1/CustomerJSOrdersREST/Alpha%20and%20Sons",
      "checksum": "A:e86aea2e0a4e74bf"
    "OrdersRest": [
        "order_number": 1,
        "amount_total": 1079,
        "paid": false,
        "notes": "This is a small order",
        "customer_name": "Alpha and Sons",
        "salesrep_id": 2,
        "@metadata": {
          "href": "http://localhost:8080/APIServer/rest/el-local/demo/v1/PurchaseOrders/1",
          "checksum": "A:5c157e88a42aa592"
        "LineItems": [
            "lineitem_id": 12,
            "product_number": 2,
            "order_number": 1,


As shown here, your code has pre-supplied context for:
  • containingRow - you can access data from the containing row, here a Customer row from the CustOrdersSvc containing Resource (line 3).  This enables you to "parameterize" the external service using locally managed data.

  • log - for debugging (such information is visible in the log)

  • restCaller.get - you can use this to invoke REST services
  • req - this is the RestRequest object, which has a number of useful properties:
return {
    baseUrl: "" + req.baseUrl,  // The URL of this call up to the project
    fullBaseUrl: "" + req.getFullBaseURL(),
    accountName: "" + req.account.getName(),
    accountUrl: "" + req.account.getUrlName(),
    projectName: "" + req.project.getName(),
    projectUrl: "" + req.project.getUrlName(),
    apiName: "" + req.apiVersion.getName(),
    userIdentifier: "" + req.userIdentifier, // May be null
    params: JSON.parse("" + req.urlParameters), // Parameters from URL, e.g. ?abc=123&def=foo
    userProps: JSON.parse("" + req.userProperties), // User props from authentication
    verb: "" + req.verb, // GET, POST, PUT, DELETE, etc...
    clientAddress: "" + req.clientAddress  // The IP address of the caller


The system does not understand the internals of the external content, including its mapping to underlying data, its primary keys, its logic its security and so forth.   The system is therefore not able to supply advanced automation services such as pagination or update.

Using local services

If you are making calls to a local service (i.e. an APICreator REST service on the same server), you should probably use SysUtility.getResource instead of making a full network call:

var custsJson = SysUtility.getResource("Customers", {filter: {"name like '%foo%' "});
var custs = JSON.parse(custsJson);
for (var i = 0; i < custs.length; i++) {
    log.debug("Customer: " + JSON.stringify(custs[i]));

This is more efficient, and it uses the same authentication as the original call. If you need to use different authentication, you will need to make a network call.

Note: Depending on whether you are using a load balancer or not, a call to your usual REST URL may or may not work. You may have to make a call to localhost, port 8080, instead.

Google ChromeScreenSnapz001.png
Val Huber,
Feb 16, 2016, 2:21 PM
Java Script Resources.png
Val Huber,
Feb 16, 2016, 2:22 PM
JavaScript Resources.png
Val Huber,
Feb 16, 2016, 2:21 PM
Screen Shot 2015-10-22 at 5.45.03 PM.png
Val Huber,
Feb 16, 2016, 2:21 PM