Maximo integration capabilities like Publish Channels , Invocation Channels provide way for invoking external service via HTTP calls.
But there are sometimes needs where external API needs to be triggered during processing logic within user interaction and continuation of user activity through API call return/processing.
Get Data from External API Call:
So we can use ScriptService
class and its method httpgetasjson to get the data from external API call and then continue maximo operation using the data requested from external api by user's activity.
service.httpgetasjson(<url>, <userid>, <headers>, <password>)
Here we can call API "URL" and pass connection and header parameters.
Here is sample code snippet :
from com.ibm.json.java import JSONObject, JSONArray
# Invoking an URL
Push Data to External API :
So we can use ScriptService
class and its method httppostasjson
to post the
data from maximo to external API call.
service.httppostasjson(<url>,<userid>,<password>, <headers>, <json>)
Here is sample code snippet
from com.ibm.json.java import JSONObject, JSONArray
# create a JSON object jsonObject = JSONObject() jsonObject.put("equipment", mbo.getString("ASSETNUM")) jsonObject.put("description", mbo.getString("DESCRIPTION")) # Invoking an URL url = "https://www.external-api.com/" userid = api-user passwd = api-pwd # Invoke URL response = service.httppostasjson(url, userid, passwd, None, jsonObject) status = response.getStatusLine().getStatusCode() obj = JSONArray.parse(response.getEntity().getContent()) if status == 200: # OK else: # error
No comments:
Post a Comment