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
------------------------------
Original Message:
Sent: Fri April 09, 2021 07:53 AM
From: Priyaranjandas Kolambkar
Subject: Acessing External System REST API Using Maximo Automation Scripts
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
Original Message:
Sent: Thu July 23, 2020 05:43 PM
From: Steven Shull
Subject: Acessing External System REST API Using Maximo Automation Scripts
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
Original Message:
Sent: Thu July 23, 2020 01:47 PM
From: Venkataraman Guruswamy
Subject: Acessing External System REST API Using Maximo Automation Scripts
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
Original Message:
Sent: Thu March 26, 2020 10:17 AM
From: Steven Shull
Subject: Acessing External System REST API Using Maximo Automation Scripts
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
Original Message:
Sent: Thu March 26, 2020 10:02 AM
From: User1971
Subject: Acessing External System REST API Using Maximo Automation Scripts
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
Original Message:
Sent: Thu March 26, 2020 08:42 AM
From: Steven Shull
Subject: Acessing External System REST API Using Maximo Automation Scripts
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.
------------------------------
Steven Shull
Director of Development
Projetech Inc
Cincinnati OH
Original Message:
Sent: Wed March 25, 2020 11:55 PM
From: keshav ravindran
Subject: Acessing External System REST API Using Maximo Automation Scripts
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