Maximo

Maximo

Come for answers, stay for best practices. All we're missing is you.

 View Only
Expand all | Collapse all

Acessing External System REST API Using Maximo Automation Scripts

  • 1.  Acessing External System REST API Using Maximo Automation Scripts

    Posted Wed March 25, 2020 11:55 PM
    I know there are lots of great material out there that showcase the power of Maximo REST API. But my question here is using Maximo automation script, how can we access another external systems Rest API. How to append the header details, the payload, etc. It would be great to share any sample scripts.

    ------------------------------
    keshav ravindran
    ------------------------------

    #AssetandFacilitiesManagement
    #Maximo


  • 2.  RE: Acessing External System REST API Using Maximo Automation Scripts

    Posted Thu March 26, 2020 06:44 AM
    An example of exactly what you're looking for from IBM:

    https://www.ibm.com/support/pages/maximo-rest-client-example-calling-external-rest-service-logo-tiger-3-maximo-client

    ------------------------------
    Frank Tate
    Gulfsoft Consulting
    ------------------------------



  • 3.  RE: Acessing External System REST API Using Maximo Automation Scripts

    Posted Thu March 26, 2020 06:57 AM
    Hi,
    It is not always a viable solution but if possible IMO the best approach is to map the REST API to a federated object:
    https://www.ibm.com/support/pages/federated-mbo-integration

    ------------------------------
    Diego Visentin
    EAM BU Director
    Tempestive S.p.A.
    Pordenone
    ------------------------------



  • 4.  RE: Acessing External System REST API Using Maximo Automation Scripts

    Posted Thu March 26, 2020 08:43 AM

    I would suggest utilizing Maximo end points. Maximo is designed to handle HTTP connections from an integration perspective, and it handles an abstracts a lot of the code portion while still giving you almost complete control of the connection. You don't need any additional libraries to be downloaded, and you know it will continue to be supported by IBM. It also gives you a good place to store information about your integration while allowing the script to override anything that is necessary. For example, we integrate with a monitoring system in two ways (retrieve monitoring IDs and another to schedule downtime for maintenance events). We're able to store the pieces that are constant in the endpoint, and override what we need to change for that particular integration (such as using a POST request instead of a GET request). 

    Federated MBOs that Diego mentioned is also a good system for certain integrations, especially if you're just retrieving information, but doesn't make sense in all cases. There's overhead in setting up a MBO that isn't necessary if you're just trying to process it in an automation script for example. And if you need to be able to update these MBOs, you have to build your own logic to push updates anyways.

    I had a response on the old forums that I'm struggling to find. This was written pretty quick, so if there are questions on it please let me know.

    The first thing you have to do is declare your endpoint in the End Points application. Create a new end point and ensure the handler is HTTP. Provide what you can in the end point configuration (such as URL, HTTP METHOD, headers, etc.). Anything that you need to set in the script, ensure that the Allow Override checkbox is checked. I've shown an example below that we use. If your service uses basic authentication, you can provide the username/password fields and it will handle that, otherwise leave those two fields null.

    Example end point
    In your script, you need to import the Router if you aren't on a newer version of 7.6 (where IBM added some additional methods on the service implicit variable to do this). You also need Java's string & HashMap imported as well.

    from psdi.iface.router import Router
    from java.util import HashMap
    from java.lang import String

    You then need to build a HashMap to override any of the properties you need to, such as HEADERS, and a body for your request (unless it's intended to be null). We built a basic handler function which I've copied below. Handler corresponds to you retrieving your endpoint, such as 
    Router.getHandler("EMXSITE24X7"). We add in the ERRORONSTATUS to our property overrides to prevent an actual exception being thrown, since we'll process the response for the issue. RESPONSE_HEADERS allows us to capture the response data to get the actual response code from the integration. In our case, anything under 400 is successful, but you may want to look at specific statuses to handle based on the integration referenced. 

    Assuming that your response is JSON, you can easily cast it into a JSONObject to make processing easier. You have to import:
    from com.ibm.json.java import JSONObject and then can do something like this: 

    responseObject=JSONObject.parse(response)

    and then access the different pieces like responseObject.get("token") if there is a JSON attribute named token. 

    def invokeEndpoint(handler,map,body):
        success = False
        response = None
        errorResponse = HashMap()
        errorMessage=""
        map.put("ERRORONSTATUS",False)
        map.put("RESPONSE_HEADERS",errorResponse)
        
        try:
            response=String(handler.invoke(map,body))
            if int(errorResponse.get("RESPONSE_STATUS"))<400:
                success=True
        except:
            errorMessage = "Error: " + str(sys.exc_info()[0]) + ". Message: " + str(sys.exc_info()[1])
        return success, errorMessage, response


    ------------------------------
    Steven Shull
    Director of Development
    Projetech Inc
    Cincinnati OH
    ------------------------------



  • 5.  RE: Acessing External System REST API Using Maximo Automation Scripts

    Posted Thu March 26, 2020 10:02 AM

    Regarding:  "Create a new end point and ensure the handler is HTTP."

    Have you found that HTTPS does not work? If so, do you know why?



    ------------------------------
    Thanks
    ------------------------------



  • 6.  RE: Acessing External System REST API Using Maximo Automation Scripts

    Posted Thu March 26, 2020 10:13 AM
    Edited by System Admin Wed March 22, 2023 11:51 AM
    What is the exception in system logs? 
    Anyway, check this https://www.ibm.com/support/pages/unable-send-outbound-transactions-over-ssl and if there is no problem for WAS to handle the destination certification (e.g. if it's a self-signed, you must import into WAS)

    ------------------------------
    Diego Visentin
    EAM BU Director
    Tempestive S.p.A.
    Pordenone
    ------------------------------



  • 7.  RE: Acessing External System REST API Using Maximo Automation Scripts

    Posted Thu March 26, 2020 10:17 AM

    All of our end points are HTTPS. There are a couple of areas that could impact people. The most common is WebSphere doesn't trust certificates unless added to the trust store.


    Beyond that, certificates greater than 2048 bits weren't allowed without replacing some policy files until relatively recent. I know with WebSphere 9 and Java 1.8 it is no longer required, not sure which earlier versions it was fixed in.

    The final thing is WebSphere 8.5.5 by default doesn't support TLS 1.2 for outbound connections which is now becoming a requirement. This was changed in WebSphere 9 but is an easy change to make in 8.5.5.

    Those are the most common things we've seen.



    ------------------------------
    Steven Shull
    Director of Development
    Projetech Inc
    Cincinnati OH
    ------------------------------



  • 8.  RE: Acessing External System REST API Using Maximo Automation Scripts

    Posted Thu July 23, 2020 04:49 PM
    Hi Steve,
    Do you have any samples to make a call to an external API to do a Oauth2 authentication and get an access token ?
    Like you said we have Oauth end points, were you able to use it at any point and sucessful ?
    Thanks a lot 
    Regards,
    Venkat

    ------------------------------
    Venkataraman Guruswamy
    ------------------------------



  • 9.  RE: Acessing External System REST API Using Maximo Automation Scripts

    Posted Thu July 23, 2020 05:44 PM

    I don't have a sample I can easily give at the moment. We did it with standard HTTP endpoints and a bit of customization to track the access token & refresh it if necessary. IBM does have an OAUTH handler that we haven't tried yet. We have it on our list to look at to see if we can transition to utilizing it to eliminate some of our customizations but haven't gotten around to it.

    At a high level overview, we setup the API manually in the third party system to get our client id, secret, & refresh token. We configured an endpoint in Maximo that hits the necessary URL to renew the access token. We created a custom object that stored the access token and when it expired (based on data we get from when we renew the access token). If the access token is going to expire within the next minute we go and renew the access token. We don't have to worry about multiple transactions as it's a single process. We then take the access token and put it on the requests as a header to interact with the system.

    The big thing is just to get comfortable with how to do it in a postman like utility and then it isn't too bad to make Maximo make a similar request.

    OAuth 2.0 was significantly easier than OAuth1.0, where we got burned by not being able to use endpoints at all. This was due to the header on an OAuth 1.0 request needing comma separated values while the HTTP handler uses commas to separate different headers. Created this RFE to hopefully help in the future: https://www.ibm.com/developerworks/rfe/execute?use_case=viewRfe&CR_ID=142699



    ------------------------------
    Steven Shull
    Director of Development
    Projetech Inc
    Cincinnati OH
    ------------------------------



  • 10.  RE: Acessing External System REST API Using Maximo Automation Scripts

    Posted Fri April 09, 2021 02:05 PM
    Hi Steven,

    We are also having a requirement for adding an OAUTH2 layer of security for integrating with an external application. Can you shed some more light as to how this can be achieved? Your explanation above is well understood but any additional details would be much appreciated.

    Regards,
    Priyaranjandas

    ------------------------------
    Priyaranjandas Kolambkar
    ------------------------------



  • 11.  RE: Acessing External System REST API Using Maximo Automation Scripts

    Posted Fri April 09, 2021 02:53 PM
    I can't do an end to end example right now, but hopefully this will provide enough context for you.
    1) We setup 2 HTTP endpoints. 1 is specific for regenerating OAUTH token and one is for making API requests

    2) For the OAUTH token one, we only needed to provide the HTTPMETHOD (POST) and the URL (which you should have from your provider). We put everything (including the refresh token) in the URL so when we invoke this endpoint there isn't anything we need to provide
    3) We invoke the endpoint a bit more complicated than some (to get specific error handling and such, see above comments) but it can be as simple as below if you're on a newer version of Maximo. This is a bit cleaner and easier to explain.

    from java.util import HashMap,Calendar
    response=service.invokeEndpoint("EMXSITE24XOAUTH",HashMap(),"")

    4) We take the response and convert it into a JSONObject so we can process it.

    from com.ibm.json.java import JSONObject
    body = JSONObject.parse(response)

    5) From there, we ​get our access token and expiration time and store it in Maximo somewhere. This could be a system property, custom object, endpoint property, etc. In our case, we store it on our custom object and in a system property for caching purposes but I've only highlighted the object syntax below since that's the critical part. If you are depending on publish channels (IE you're not invoking your endpoint from an automation script) then you need to store the access token on the header of the endpoint. 

    emxCredMbo.setValue("ACCESSTOKEN",body.get("access_token"),emxCredMbo.NOACCESSCHECK)
    calExpiration = Calendar.getInstance()
    calExpiration.add(Calendar.SECOND,body.get("expires_in_sec"))
    emxCredMbo.setValue("TOKENVALIDUNTIL",calExpiration.getTime(),emxCredMbo.NOACCESSCHECK)

    6) In our use case, we're invoking the endpoint to make the request from our automation script. So we then invoke the endpoint in question, similar to above, but this time providing the access token in our HashMap()
    map=HashMap()
    map.put("HEADERS","Authorization: Zoho-oauthtoken " + authToken)


    ------------------------------
    Steven Shull
    Director of Development
    Projetech Inc
    Cincinnati OH
    ------------------------------



  • 12.  RE: Acessing External System REST API Using Maximo Automation Scripts

    Posted Sat April 10, 2021 09:33 AM
    Thank you Steven, much appreciated. I will try this out and will keep you posted on this forum.

    Regards,
    Priyaranjandas

    ------------------------------
    Priyaranjandas Kolambkar
    ------------------------------



  • 13.  RE: Acessing External System REST API Using Maximo Automation Scripts

    Posted Mon May 31, 2021 11:10 AM
    How do we do a dynamic URL from script? I need to add paramaters to my endpoint URL.
    ?type=TRUCK&label=1001

    ------------------------------
    Jean Lau
    ------------------------------



  • 14.  RE: Acessing External System REST API Using Maximo Automation Scripts

    Posted Thu March 26, 2020 10:06 AM
    Here is a related post:

    Maximo/GIS spatial query
    https://stackoverflow.com/a/57730617/10936066

    Also, take a look at page 2 in this PDF:  Maximo 76 Scripting Features:

    https://www.ibm.com/developerworks/community/wikis/form/anonymous/api/wiki/02db2a84-fc66-4667-b760-54e495526ec1/page/03ad118c-6040-43dd-bc6d-d7a03510d135/attachment/1004fd2b-1b51-411e-8df0-a8b02ca86272/media/Scritping76Features%20%285%29.pdf


    ------------------------------
    Thanks
    ------------------------------



  • 15.  RE: Acessing External System REST API Using Maximo Automation Scripts

    Posted Thu March 26, 2020 03:06 PM
    hi, you will implement an invocation channel to interact with a remote endpoint. Details are specific to the requirements. hth -Keith-

    ------------------------------
    keith simmons
    ------------------------------



  • 16.  RE: Acessing External System REST API Using Maximo Automation Scripts

    Posted Thu March 26, 2020 04:14 PM
    Thanks for the question , Keshav.
    Are you looking to send Maximo data by invoking an external application API  ? You can very well achieve it by using MIF.

    All you need is setup an HTTP end point in Integration-> End points with PUT or POST method, followed by a publish channel and External application.
    If you wish to proceed with automation script approach, here is the link--> https://www.ibm.com/support/pages/node/1129845
    Maximo Rest Client Example: Calling an External REST Service (Logo Tiger 3) with a Maximo Client

    The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. www.wipro.com