Hitachi

JP1 Version 12 JP1/Integrated Management 2 - Manager Command, Definition File and API Reference


4.5.1 jp1Imdd.callRest

This method calls a REST API. The following table shows the details of the jp1Imdd.callRest method.

Method name

Object jp1Imdd.callRest(String method, String url, Object headers, String body)

Parameters
method

A method of a REST API

url

The URL of the REST API

_headers

The request header of the REST API

body

The request body of the REST API

If the GET method is specified and the body is not needed, set body to null or an empty character.

Return values

An object that stores the response from the REST API.

The object contains the following keys and values:

No.

Description

Key

Value

1

If the REST API is completed successfully

"response"

response object

Keys and values that are stored in the response object

"status"

HTTP status code

"headers"

response header

"body"

response body

2

If the analysis of the URI fails

"error"

error object

Keys and values that are stored in the error object

"status"

0

"body"

string indicating an analysis error

3

If the HTTP status code is 4xx or 5xx, or an unknown status code is returned

"error"

error object

Keys and values that are stored in the error object

"status"

HTTP status code

"headers"

response header

"body"

response body

Exception
RestClientException
  • When an I/O error occurs

Call example
module.exports = function(args) {
    var baseUrl = args.baseUrl;
    var manager = args.manager;
    var jp1token = args.jp1token;
 
    var method = 'POST';
    var apiPath = '/v1/authorization/token';
    var url = baseUrl + apiPath;
    var headers = {
        'Accept': 'application/json',
        'Content-Type': 'application/json',
        'X-AJS-Authorization-Token': jp1token,
    };
    var body = {
        parameters: {
            manager: manager,
            serviceName: 'AJSROOT1',
        }
    };
    return jp1Imdd.callRest(method, url, headers, JSON.stringify(body));
}