Planning Analytics

 View Only

Planning Analytics Engine - ExecuteHttpRequest GET Example

By Edward Stuart posted Fri October 13, 2023 08:03 AM

  

In my last post we looked at the structure and a little of the theory behind ExecuteHttpRequest:

https://community.ibm.com/community/user/businessanalytics/blogs/edward-stuart/2023/10/07/executehttprequest

We will now look into a GET request from within the Planning Analytics Engine:

Here is the code:

sBaseUrl = 'https://' | sTerritory | '.aws.planninganalytics.ibm.com/api/' | sTenantId | '/v0/tm1/' | sModelName | '/api/v1/';

sObject = 'Cubes';
sObjectName = 'Control';
sSuffix = '(''' | sObjectName |''')';

sFilter = '/Name/$value';

sURL = sBaseUrl | sObject | sSuffix | sFilter;

ExecuteHttpRequest( 
  'GET', 
  sURL,
  '-h Content-Type:application/json',
  '-h Authorization: Bearer ' | sAccessToken
  );

sCubeStatus = HttpResponseGetStatusCode;
sCubeResponse = HttpResponseGetBody;

sCubeHeaderContentType = HttpResponseGetHeader( 'Content-Type' );

ASCIIOutput( sFolder | 'GetCubeDetails.txt', NumberToString(sCubeStatus ));
ASCIIOutput( sFolder | 'GetCubeDetails.txt', sCubeHeaderContentType );
ASCIIOutput( sFolder | 'GetCubeDetails.txt', sCubeResponse );

The output from this TI process can be found in the "GetCubeDetails.txt" file in the File Manager (https://www.ibm.com/docs/en/planning-analytics/2.0.0?topic=2wnj22-manage-files-file-manager):

"200"
"text/plain; charset=utf-8"
"Control"

Before we can start making these requests we need to "Establish API connectivity for Planning Analytics as a Service", we can do this via the documentation here:

https://cloud.ibm.com/docs/planning-analytics?topic=planning-analytics-api_connectivity

This establishes the details for the BaseURL, the Territory and the Tenant. We know the modelname and any of the objects we want to query, in this example I am querying a "Control" cube I have created.

The query I am constructing follows the OData standard and resolves to:

Cubes('Control')/Name/$value

More details on OData queries can be found here - https://www.odata.org/getting-started/basic-tutorial/#property

The expected result from this query is the Name of the Cube I have passed - Control

So far, we have established the BaseUrl and the Object I want to query (a Cube) and the Property of the Object (the Name).

Now we need to establish the Headers for the request, the content-type of the requested data and how we have authenticated the request.

The Content-Type is application/json

The Authorization Header uses a Bearer Token which is obtained by making a authorization request to an IBM Cloud End Point:

https://iam.cloud.ibm.com/identity/token?apikey={{API_KEY}}&grant_type=urn:ibm:params:oauth:grant-type:apikey

We will cover this aspect in another blog post, this creates an Access Token which is valid for 3600 seconds or 1 hour

I have returned the HttpResponseGetStatusCode, HttpResponseGetBody and HttpResponseGetHeader as examples to review how they work and then exported these values to a text file in a nominated folder within File Manager.

After the last blog post it was confirmed that a JSON parser would be coming so the activities I will cover will avoid moving data/ attributes for the time being until this is made available.

Let me know if you have any questions on the above,

Edd

2 comments
18 views

Permalink

Comments

Thu October 19, 2023 05:49 AM

A good point, the theory being that we could automate accessing the AsciiOutput file instead of continually downloading the same filename.

I'll make a forum post on this as I think it is possible but not by design. The short version is that ReturnCSVTableHandle is a drill through function which means we need to create the drill through process and rules.

A file is not available as a datasource for a drill through so we need to run an API request to ExecuteRelationalDrillThrough to return the file we are after and finally present it to the user

Wed October 18, 2023 05:48 AM

Thanks for the insights Ed.
Was wondering if you could use the ReturnCSVTableHandle function in your code to pop up the window with the details written to the GetCubeDetails.txt file reducing the clicks needed to view via the File Manager.