Toggle menu

apiclient

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 this.callWorkerMethod() which is part of the End Point this Object. It's much easier to use and also parses the result

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:

NameDescription
userUsername for authentication*
passwordPassword for authentication*
apiKeyAPIKey for access*
idPrefix on the JSONRPC2 request ID
serverThe base address of the API Server. This value only needs to be provided if calling services on a remote API Server
serveridUsed 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;
}

Last modified on 01 August 2023

Share this page

Facebook icon Twitter icon email icon

Print

print icon