Toggle menu

End Point this Object

The end point "this" object provides properties and functions you can use within your end point.

this.callWorkerMethod(workerName, methodName [,params, advanced])

Performs a JSON RPC call to another worker on the same API Server.

ArgumentTypeDescription
workerNameString, requiredThe name of the worker to call
methodNameString, requiredThe method to call on the worker
paramsObject, optionalThe method parameters
advancedObject, optionalurlString, optionalOverrides the base API Server URL
rawModeBoolean, optionalDefaults to false. If true the full result will be returned without parsing, see below
optionsObject, optionalapiKey - a key to supply with the request
user - a username to supply with the request
password - a password to supply with the request

async function(params, credentials) {
    return await this.callWorkerMethod("icmapi", "CSArticle_get", {
        "get": "ArticleHeading",
        "set": {
            "ArticleID": 1
        },
    }, {
        "options": {
            "apiKey": "83A9ABB3-xxxx-xxxx-xxxx-9E2E7673137F",
        }
    });
}

rawMode

callWorkerMethod "understands" the format of responses it gets back from other workers and can processes them:

  • If the response contains a "result" property, that is returned. If it contains multiple, nested, result properties, the final one is returned
  • If the request was made to the iCM API worker, the function will look for and return the "multipleItemData" or "itemData" properties

This behaviour can be disabled by setting "rawMode": true

this.config.apiServer

Read-only access to the API Server configuration information.

this.config.worker

Read-only access to the worker configuration information (that is, the worker the end point is deployed to).

this.config.env

Read-only access to the environment configuration information. This includes useful information like:

  • Mail server and default "from" address
  • iCM URL
  • API Server URL
  • Solr URL
  • Datasource information
  • Locale
  • User Profile form

this.devMode

Returns true if the end point is published (deployed) in development mode.

this.getLock(lockName[, numId, timeoutInSecs])

A function that obtains a named, cluster wide, lock. It will return true if the lock is obtained, false if not. Locks are released automatically when the end point function returns or throws an exception.

this.invokeEP(endPointName[, params, credentials])

A function used to call another end point (including internal end points) on the same worker. The first parameter is the name of the end point to invoke. Additional parameters can be passed to the end point in a JSON object.

Using this function is very efficient as it doesn't involve making an API Server request; it's just a JavaScript call. In addition, it doesn't tie up another end point worker instance, there is no potential for deadlocks, and it returns exactly what the invoked end point returns.

function(params, credentials) {
    let resp = this.invokeEP("tim.iCMAPI.CSArticle", {
        "articleID": 51
    });
    return resp;
}

this.log(message[, object, customLogfile])

There are various versions of this function, with the function name setting the logging level, one of: logError, logWarn, logInfo, logVerbose and logDebug.

These functions output messages and information to the API Server console, and optionally to a file. The logVerbose and logDebug level messages will only appear if consoleTraceLevel and fileTraceLevel are set to the appropriate level in the API Server configuration.

The message appears in the trace view and the elements in the object in the trace line's popup (the "Data available link in the console). The customLogfile can be downloaded from the console's Log tab.

For example:

function(params, credentials) {
    let myVariable = "myValue";
    this.logError("Some text to log", {"myVariable": myVariable}, "myNewLogFile");
}

Would log this to the console's trace display:

End Point Log
 

Clicking the cog icon displays more details. Our object has been added to the existing default properties.

End Point Log Details
 

See the End Point Trace and Log knowledge base article for a more detailed look at tracing and logging.

this.releaseLock(lockName)

A function that releases a named lock previously created using getLock. Only locks owned by this end point can be released.

this.releaseLocks(lockNames)

This version can be passed an array of lock names.

this.serverid

The unique identifier of the API Server the end point is executing on. This is needed to perform internal requests using the apiclient library.

Last modified on August 28, 2024

Share this page

Facebook icon Twitter icon email icon

Print

print icon