Script handler
The REST API can support most use cases for retrieving or processing data through simple configuration. Occasionally, scenarios exist where retrieving or processing data is difficult to do by using existing APIs. In those cases, you can create a script and not a launch point.
You can call the script with either a GET or POST, for example:
https://myurl.com/maximo/api/script/SCRIPTNAME?lean=1
The following table lists the implicit variables.
Variable name | Description |
---|---|
request | OslcRequest representation of the request that is made. This variable shows important methods such as request.getQueryParam(“parameter”) and request.getHeader(“header”) to retrieve values that are provided as a query parameter or header. You can also access the UserInfo by calling request.getUserInfo(). |
requestBody | A string representation of the data submitted on request for POST, PATCH, PUT |
httpMethod | Whether this method was a GET, POST, PUT, and so on. Can also be retrieved by calling request.getHttpMethod(). |
responseBody | The script sets this variable as either a byte[] or String to return in the response. This variable is not required if you do not intend to return a response. |
responseHeaders | The script can provide more headers to this HashMap to return to the calling application. |
The following example script changes the user's default insert site based on the query parameter.
# This example changes the user's default insert site based on the query parameter.
# This is different from setting it on the MAXUSER record because this updates for the current session.
from psdi.server import MXServer
maxServer=MXServer.getMXServer()
siteid=request.getQueryParam("siteid")
if siteid and maxServer.isValidSite(siteid):
userInfo=request.getUserInfo()
userSet=maxServer.getMboSet("MAXUSER",userInfo)
userSet.setQbeExactMatch(True)
Call with a GET/POST request like the following example:
https://myurl.com/maximo/oslc/script/setinsertsite?lean=1&siteid=BEDFORD