What’s New in Oracle Policy Automation August 2017 #2

What’s New in Oracle Policy Automation August 2017 #2 (OPA REST API)

I’ll be entirely honest and say that this post has more to do with finding a good method to describe practical uses for the REST API that would be both interesting and entertaining, than it has with specifically focusing on what is new in Oracle Policy Automation August 2017. But since the OPA REST API is really coming into it’s own in the latest versions, it seems appropriate to file this under the heading of What’s New.

So I fired up Microsoft Visual Studio and decided to challenge myself to provide some code and demonstration that shows how to use the OPA REST API in Visual Basic. I decided to focus on the Deployment API, but wanted to get there in a set of logical steps : basic use, getting structured data out, authenticating your user and finally getting a Zip file to download.

For the Hub REST API, you need to create an integration user. For deployments, the caller needs the Deploy Admin role for the collections they want to access.

I’ll repeat what I said in the video; I’m no programming professional – although I can code my way through most things – and this is a late night experimental plaything, so don’t expect much in the way of clean structure. With that proviso, here are the four challenges.

OPA REST API – Deployment API First Steps

  1. Make a simple call to the API for example in order to retrieve the version information, and see if we can dump the output somewhere

This part is all about the mechanism to actually call the the REST API. The output is just a nice thing to prove it works.

OPA REST API - Get basic about information

From the above snippet, you can see the basic principle : create a WebRequest and build the URL, before asking for the response. The response can be read from the responseStream, and converted into a string before being displayed in a text box on a form.


OPA REST API – Deployment API More Data

So the next step in the learning curve of OPA REST API is to grab more content, and then format it in some way. We are going to get the list of endpoints and the corresponding URLs. The structure is hierarchical, an array of items, and each item has an array of links. For this, we will use a couple of classes to help us define two concepts : the items in the response and the links which are children of the items.

OPA REST API - Get Items and Links

In the above example, the same technique is used to make the request, but the response is deserialized into items and then each item is inspected for links. Since each item has three links and the third one is the link I want to display, I grab that one.

OPA REST API – Deployment Get Authenticated

In the next example, I want to show how to obtain the OAuth2 authentication access token. Most people will not have their Oracle Policy Automation Hub with anonymous access, so this is a very important step.

OPA REST API - Get Authentication

In the example above, the token is parsed out of the response using a different method, grabbing the element through the key to identify it. In this case the response is simple and is not an array.

OPA REST API – Deployment API Download a Snapshot as a Zip

Finally, now that I was able to do all of that, I wanted to make some magic happen. If I can authenticate, let’s go get a deployment as a Zip file and programatically download it.

OPA REST API - Get Zip File

In this final example, the request accepts “application/zip” and the response is grabbed as a memory stream and sent to a file. The folder has to exist but the ZIP file will be created there.

OPA REST API – Deployment API Conclusion

Although this started out a little exercise, I very quickly became a big fan of the OPA REST API – the prospect of being able to undertake so many different tasks (remember that there is a batch assessment API as well as user API) and/ or to programmatically instance them opens up new and powerful avenues for anyone looking to strengthen their DevOps processes around Oracle Policy Automation.

The video below is the code in action, and the result. Anyone who is interested in getting a copy of the code, just leave a comment. No warranty or fitness for purpose implied, but I hope the community will take it as it is intended : as a learning objective about the OPA REST API.


Until next time on the OPA Hub Website, have a great day!

Richard Napier

Author: Richard Napier

After 8 years in case management and ERP software roles, Richard Napier joined Siebel Systems in 1999 and took up the role of managing the nascent Siebel University in Southern Europe. He subsequently was Director of Business Development and Education for InFact Group (now part of Business & Decisions) for 8 years. He now runs Intelligent Advisor IT Consulting OÜ. Owner of intelligent-advisor.com, he also is Co-Founder of the Siebel Hub.

4 thoughts on “What’s New in Oracle Policy Automation August 2017 #2

  1. This is definitely a great tutorial. I could follow and get all these done at my end. Thanks.

    However, I am trying to create a new deployment from another existing one. So, I followed the steps as below:

    1. GET the deployment using ReST API
    2. Copy the response to the body of a new POST request after changing the name etc.
    3. Fire the POST request.

    However, I am getting errors on this. Do you have a sample for this?

    1. Hey There. If I find the time in the next few days I will put one up on the site, I will basically add the steps you mention (download, then upload with another name) and publish it here. Before I do that however, have you a) eliminated all possible errors such as authentication problems and b) can you share with me the exact nature of the error you are getting? You can email any screenshots or error logs to help@theopahub.com as that will obviously help 🙂 Thanks for reading the OPA Hub!

        1. Well I can’t really help with PowerShell exactly (although I know you can POST json to URLs with PowerShell) but I have two new articles publishing this week that look at exactly this scenario (uploading a Zip deployment) using Visual Basic :- hopefully the articles will show you the way to work, and give you some hints. First one publishes on Monday 25, then on Tuesday 26 June 2018.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Serving Customers Worldwide
Hide picture