OPA Hub - Deployment REST API VB Debug 1

Deployment REST API : Uploading Zip Files #2

Following on from the previous post, we are now in a position to begin putting together the different elements and actually working out how to use the Deployment REST API to upload a Zip File programatically. As I have said on many occasions I’m most definitely not a coder, but I like to explore and often it helps me in my day job : if I can piece together a plan and show that it works, other more intelligent people can get behind it. All of that means that any code I share (and you are welcome to post a comment and I will forward it to you) is strictly for entertainment and educational purposes only.

Back to our challenge, and here is our strategy.

  1. Ask the user for a Zip File
  2. Base64 encode the Zip File
  3. Use the Authentication mechanism from last time, log the user in to the Oracle Policy Automation Hub
  4. POST the request
  5. Observe the Response in the Oracle Policy Automation Hub and in our code
  6. Debug any issues

Building the Solution

The only thing to remember is that you need a snapshot file from the Deployment page, but even I know how to display a Windows Dialog and grab the file name.

OPA Hub - Deployment REST API Get File

2. Base64 encode the Zip File, as we mentioned in the previous post.

3. Use the authentication mechanism as we did in the original post. If you are struggling with the concepts behind it, read the section about debugging further on in this article.

4. POST the Request. Nothing much to see here, except the need to instantiate all the different elements of your Visual Basic Class before you serialize the whole thing into JSON. In the image below, I’m using the Classes generated in JSONUtils and building my structure before serializing it into JSON.

OPA Hub - Dep;loyment REST API example code

The actual POST comes from the Stack Exchange code I linked to in the previous article, with a few minor modifications.

OPA Hub - Deployment REST API POST Request

5. Observing the response is pretty easy, since you should now have a new Deployment in your Oracle Policy Automation Hub. Can you guess which ones in the screenshot below came from my code?

OPA Hub - Deployment REST API Result

6. Debugging

Of course, this is going to be the place where you might spend a lot of time. And of course, the Visual Studio debugger is your friend. But part of the challenge is the lack of detail. For example, it’s good to know you have a 409 Error, or a 400 Error. But what the heck does it mean. This is where your toolset will come in very handy.

a. Use SOAP UI

SOAP UI can be used to make and debug REST API calls. The process is a little different to the SOAP calls of the past, and it is important to note that you will need to create an Authentication Profile with your Oracle Policy Automation integration user account, and check that you have a valid token before you begin. If you are new to this, the OPA Hub Website has some good news for you. In our series of articles about Web Services and integrating with other applications, we videoed a typical scenario of using SOAP UI for deployment REST API calls. Scroll down to the video labelled “REST API Services”.

b. Grab your base64

Using your Visual Studio debugger and the variable content viewer for example, grab the encoded Zip File from your session:

OPA Hub - Deployment REST API VB Debug 1

Then paste it into a REST request in SOAP UI that has a valid token, and observe the response. Way more useful and a good guide to coding your error handling in Visual Studio.

OPA Hub - Deployment REST API SOAP UI Debug 1

So what about a self-congratulatory video to finish. If you want the code, just leave a comment and I will happily provide it to you.