Platform Rest API

Following rest APIs are provided

  • SendMessageToCLH
  • ReceiveMessageFromCLH
  • ReceiveSENFromCLH

These APIs are secured by Oauth 2. A valid Oauth token is required to be passed while invoking these APIs.

Retrieve Oauth Token

Oauth token can be retrieved from URL https://ppus.bhumaitc.com/auth/token by posting following request:

Headers:

– Content-Type: application/x-www-form-urlencoded

– Authorization: Basic Base64Encoded(<clientId>:<clientSecret>)

Parameters:

– grant_type: client_credentials

API returns a JSON response with access_token. Extract the access token for invoking Platform’s rest APIs

Sample Java Code:

This code uses Apaches OLTU library:

OAuthClient client = new OAuthClient(new URLConnectionClient());
String auth = clientId + ":" + clientSecret;
String authentication = Base64.getEncoder().encodeToString(auth.getBytes());
OAuthClientRequest request =
	OAuthClientRequest.tokenLocation(“https://ppus.bhumaitc.com/auth/token”)
	.setGrantType(GrantType.CLIENT_CREDENTIALS).buildQueryMessage();
request.addHeader("Accept", "application/json");
request.addHeader("Content-Type", "application/x-www-form-urlencoded");
request.addHeader("Authorization", "Basic " + authentication);
String token = client.accessToken(request, OAuthJSONAccessTokenResponse.class)
                            .getAccessToken();

Invoking SendMessageToCLH API

Post following request at URL https://ppus.bhumaitc.com/api/v1/message/send-to-clh

Headers:

– Content-Type: application/json

– Authorization: Bearer <access_token>

Request Body:

{

message:<JSON escaped message>

}

You can use any tool to JSON escape the XML message.

Sample Java Code:

JSONObject jsonReq = new JSONObject();
jsonReq.put("message", message);
URL apiUrl = new URL(“https://ppus.bhumaitc.com/api/v1/message/send-to-clh”);
HttpURLConnection urlConn = (HttpURLConnection) apiUrl.openConnection();
urlConn.setDoOutput(true);
urlConn.setDoInput(true);
urlConn.setRequestProperty("Authorization", "Bearer " + accessToken);
urlConn.setRequestProperty("Content-Type", "application/json");
urlConn.setRequestProperty("Accept", "application/json");
urlConn.setRequestMethod("POST");
try (OutputStreamWriter osWriter = new OutputStreamWriter(urlConn.getOutputStream())) {
    osWriter.write(jsonReq.toString());
    osWriter.flush();
}

Invoking ReceiveMessageFromCLH API

Post following request at URL https://ppus.bhumaitc.com/api/v1/message/receive-from-clh

Headers:

– Content-Type: application/json

– Authorization: Bearer <access_token>

The API returns messages corresponding to the client as a JSON response in following format

Parameters:

{

messages: array of <JSON escaped message>

}

Sample Java code:

List messageList = new ArrayList<>();
JSONObject jsonReq = new JSONObject();
URL apiUrl = new URL(“https://ppus.bhumaitc.com/api/v1/message/receive-from-clh”);
HttpURLConnection urlConn = (HttpURLConnection) apiUrl.openConnection();
urlConn.setDoOutput(true);
urlConn.setDoInput(true);
urlConn.setRequestProperty("Authorization", "Bearer " + accessToken);
urlConn.setRequestProperty("Content-Type", "application/json");
urlConn.setRequestProperty("Accept", "application/json");
urlConn.setRequestMethod("POST");
try (OutputStreamWriter osWriter = new OutputStreamWriter(urlConn.getOutputStream())) {
    osWriter.write(jsonReq.toString());
    osWriter.flush();
}
try (BufferedReader br = new BufferedReader(new 	InputStreamReader(urlConn.getInputStream()))) {
    String jsonStr = IOUtils.toString(br);
    JSONObject messageJson = new JSONObject(jsonStr);
    JSONArray messageArray = messageJson.getJSONArray("messages");
    for (int i = 0; i < messageArray.length(); i++) {
        messageList.add(messageArray.getString(i));
    }
}