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.
Argument | Type | Description | ||
---|---|---|---|---|
workerName | String, required | The name of the worker to call | ||
methodName | String, required | The method to call on the worker | ||
params | Object, optional | The method parameters | ||
advanced | Object, optional | url | String, optional | Overrides the base API Server URL |
rawMode | Boolean, optional | Defaults to false. If true the full result will be returned without parsing, see below | ||
options | Object, optional | apiKey - 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
- 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
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
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:
Clicking the cog icon displays more details. Our object has been added to the existing default properties.
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.