Forum Stats

  • 3,853,831 Users
  • 2,264,280 Discussions
  • 7,905,460 Comments

Discussions

Using Jython for Essbase Cloud Service REST API Dataload

Craig Maxey
Craig Maxey Member Posts: 4 Blue Ribbon
edited Aug 28, 2019 6:27PM in Financial Data Management

Hi all...first post here so hope this is acceptable. 

I’m trying to write a jython script in FDMEE to make a REST call to the Essbase cloud service for a streaming DataLoad.  I am successfully initiating the stream (I think) as I am getting a JSON response back with a streamID.  However, when I then send the next POST request to that streamID (including a comma delimited string as payload), I get back the response with an error code 400 and JSON including an error Message of ‘Stream id ‘123456’ does not exist’.  This is true of both the POST request to stream data and also the DELETE request to stop the stream.

I am using the urllib and urllib2 libraries in jython but have also tried httplib as well with similar results.

Question:  Does anyone have any experience with this particular REST API call?  I feel like I’m missing something very obvious. 

Applicable piece of Jython script:
baseURL='https://OACpath/essbase'
restEndPoint='rest/v1/applications/appapp/databases/cubecube/dataload'
restURL=r"%s/%s" % (baseURL,restEndPoint)

#Dictionary for request body
bodyDict = {}
bodyDict['ruleFileName'] = ‘rule_test'
PayLoad=JSONObject(bodyDict)
str_payload=str(PayLoad).encode('utf8')

request=urllib2.Request(restURL)
request.add_header('Authorization', authHeader)
request.add_header('Content-Type','application/json')
request.add_data(str_payload)

try:
  urlHandler=urllib2.urlopen(request)
  time.sleep(3)
  response = urlHandler.read()
except urllib2.HTTPError, e:
  fdmAPI.logInfo('code: %s, desc: %s' % (e.code,e.read()))
  fdmAPI.logIfno('full url: %s' % (request.get_full_url())) 

sid = string containing streamId parsed out of response from prev call.
newRestURL=r"%s/%s/%s" % (baseURL,restEndPoint,sid)
samp="comma delimited data"
request2=urllib2.Request(newRestURL)
request2.add_header('Authorization', authHeader)
request2.add_header('Content-Type','text/plain')
request2.add_data(samp)

try:
  urlHandler2=urllib2.urlopen(request2)
  response2= urlHandler2.read()
  fdmAPI.logDebug(response2)
except urllib2.HTTPError, e:
  fdmAPI.logInfo('code: %s, desc: %s' % (e.code,e.read()))
  fdmAPI.logInfo('full url: %s' % (request2.get_full_url()))
  fdmAPI.logInfo('headers: %s' % (request2.header_items()))

Answers

  • JohnGoodwin
    JohnGoodwin Member Posts: 30,471 Blue Diamond
    edited Aug 27, 2019 2:53PM

    When I used used the streaming option to load to Essbase cloud in the past I had to keep the session alive so the stream ID is still valid, once the session is closed the stream ID is destroyed that is why you get the message the stream ID does not exist.

    Cheers

    John

  • Craig Maxey
    Craig Maxey Member Posts: 4 Blue Ribbon
    edited Aug 28, 2019 6:27PM

    I have done everything I can think of to keep this session alive but am not having any luck.  I added a header for {Connection:keep-alive} and it's returning the same header in the response but no luck with a valid streamID. 

    Anyone out there done this exercise in Jython/Python using httplib or urllib/urllib2 libraries that has encountered this issue?

    What's intriguing is that if I use the 'try it out' functionality in the Swagger documentation of the REST api for Ess CS, it works, so i'm fairly confident it's a syntax thing with the jython library.

    Thanks all!