Sunday, July 8, 2018

Introduction to outline editing using JSON and REST apis

In this blog, we will cover how we can automate the outline editing using simple JSON file and REST apis.

Read more about JSON here: https://www.json.org/
and REST apis here: https://en.wikipedia.org/wiki/Representational_state_transfer

We will use cURL for executing the outline REST. cURL is a command line library to execute HTTP requests.
https://en.wikipedia.org/wiki/CURL

cURL is installed by default on the Linux systems but on windows, you have to download and install it before trying the examples. https://curl.haxx.se/download.html

If you want to try any REST clients like POSTMAN etc., you can skip the cURL installation.

 Create a simple JSON file on your system with below code snippet.
{
  "editActions" : [
     {
        "mbrAdd" : {
                            "mbrName" : "Test", "parent" : "Product"
                       },
        "mbrRename" : {
                           "thisMbr": "Test", "mbrName":"Test1"}
     }
   ]
}

In this JSON, we are trying to add a member called "Test" in Product dimension and renaming it to "Test1".  This example will work on any outline with Product dimension in it.


Now, let's run this.
Save the above JSON into a file called myBOE.json. We can name it anything though.

Open command prompt and run it like below:

suresh@mylaptop:/mnt/d/study/Essbase/boe$ curl -X POST -u <username>:<password> "https://<host>/essba
se/rest/v1/applications/<application>/databases/<database>/boe" -HAccept:application/json -H Content-Type:application/json --data "@
/mnt/d/study/Essbase/boe/myBOE.json"
{
  "messages" : "Info [1370001]: at line 2 char 111 element[otlEditMain], outline version reset to [0].
   Total member added: 1
   Total member updated: 1
   Total member deleted: 0
   Total XML edit time:[0.010000]"
}

Replace <username> with your username, <password> with password <host> with your OAC host, <application> with your Essbase application and <database> with database/cube name.


Yay! we got the output saying a member is added and updated. I don't believe, it's that simple. Let's confirm if it's real in the outline user interface :-)


Nice! It added and renamed a member.

To see what one can do and what are all the elements we can put in the JSON, click the below link:
https://drive.google.com/file/d/1Qs-T6_K3mamXuOq0hpghzsxYUL6pHd6b/view?usp=sharing

Happy learning!!!

  

No comments:

Post a Comment