This module is used to send a request to a service on an API Server.
Note that if you are working in end points, you should use
Executed
Server-side.
Details
const apiclient = require('apiclient');
Once loaded the apiclient module is used to create a new API Server Client:
let client = new apiclient.ApiClient(options);
Where options is an object with the following optional properties:
Name | Description |
---|---|
user | Username for authentication* |
password | Password for authentication* |
apiKey | APIKey for access* |
id | Prefix on the JSONRPC2 request ID |
server | The base address of the API Server. This value only needs to be provided if calling services on a remote API Server |
serverid | Used when calling a worker assigned to the internal key |
* see API Server Security for more information |
Methods
Once loaded the following methods can be called from the client.
Invoke
Invokes the iCM Java API, used to call worker services on the API Server.
let request = client.invoke('service', 'method', parameters);
- service - the name of the service (usually the name of a worker). This can include a full URL, like "http://myserver:5706/ajaxlibrary"
- method - the method to be called on that service
- parameters - an array or object of parameters passed to the method
Example
A request invoking the icmapi worker would be constructed as follows. In this example we are calling a worker secured by a username and password
function(params, credentials) {
const apiclient = require('apiclient');
let client = new apiclient.ApiClient({
user:'MyUser',
password:'MyPassword'
});
let request = client.invoke('icmapi', 'CSArticle_get', {
'get':'ArticleHeading',
'set':{
"ArticleID":304,
},
});
return request;
}