Groovy, REST and HPCM: POST

Now that the KScope hangover is done with, I thought we’d look at another example of how REST with Groovy works. Today, we will look at another example using the HPCM REST API; this one deals with executing tasks, such as running rulesets. While our earlier example used the “GET” method, we now will be using the “POST” method.

The POST method requires not just the URL, but also a payload (or parameters) that needs to get passed to the URL. So, not as simple as the “GET”. According to the documentation, the syntax looks like below.

26_1_Doc

Before we get to the payload, let’s make sure we have the right URL. The format for the URL is:

http://{HostName}/profitability/rest/v1/applications/{applicationName}/povs/{povGroupMember}/jobs /runLedgerCalculationJob

which might translate into the example below:

http://unlk.cube.com:19000/profitability/rest/v1/applications/EntOH/povs/December_FY15_Actual_Final/jobs/runLedgerCalculationJob

Now, let’s look at the payload. Payload parameters need to be passed through to the URI in JSON format. How can we do this? First off, we need to import a JSON library (download and place it in the Groovy library, if not already available).

26_2_JSON_Library

This will allow us to set up the parameters in JSON format, so that the URL can understand them. The code might look like the screenshot below. The “put” actions below add the individual parameters needed for the payload (scroll up to the documentation screenshot. You should see a direct correlation between the “put” actions and the parameters needed for the POST).

26_3_Code_1

Finally, to push the payload into the URL, we use the code below.

26_3_Code_2

If we add all those pieces of code together, we might get something that looks like this:

And if we execute it from the Groovy console, we get the output below.

26_4_Results

Finally, if we check on the job library from Workspace, we see the job results as well.

26_5_Results

The code is pretty basic and I highly recommend adding error trapping logic to your code (that’s for another day). You should also check for job completions IMO. You can also add this to ODI procedures (as I showed here) and take your integrations to the next level. If you want to learn more about REST and Groovy, please follow posts from the immense Jake Turrell and the delightful Joe Aultman. They do sterling work in this area.

Avatar

About Vijay Kurian

Known as the Clem Fandango of EPM consulting, Vijay Kurian has been developing enterprise solutions for companies for the last 12 years (increment years if reading post-2015). Having worked with Essbase, Planning, DRM and other assorted technologies during that time, he’s made the frankly, average decision, to write about them. He is, surprisingly, an Oracle ACE Associate. He hopes to contribute frequently to US Weekly, People and Sensible Chuckle magazines on improving reporting solutions, creating master data management systems and zzz…

Leave a Reply

Your email address will not be published. Required fields are marked *