Hello Jim, thanks a lot for the above information. I will try these out.
Original Message:
Sent: Fri September 29, 2023 11:08 AM
From: Jim Boland
Subject: Python Cognos Analytics with REST API
Yes...ish.
You have two options when making request to CMS - you can have them run synchronously, or asynchronously.
Details on the async options are here.
The easiest to use, is to specify synchronous, by adding an async=off
query parameter to your request. Example:
https://us3.ca.analytics.ibm.com/bi/v1/disp/rds/outputFormat/report/i15E936FAE97A43AE88385CADB5B7807E/PDF?p_product=Earl%20Grey&p_type=Black%20tea&async=off
Running synchronously, will cause your request to block waiting for the report to complete execution, then return the result (as a response to this initial request).
You can also run it asynchronously. If you add async=MANUAL
, instead of waiting for (and returning) the report output, it will immediately return an XML response that looks like this:
<rds:receipt><rds:status>working</rds:status><rds:url>../../../../rds/sessionOutput/conversationID/iE9F2D01E5EE643ABAD08BB13BB13AA2C</rds:url><rds:conversationID>iE9F2D01E5EE643ABAD08BB13BB13AA2C</rds:conversationID></rds:receipt>
You can then poll the url returned (e.g. https://us3.ca.analytics.ibm.com/bi/v1/disp/rds/sessionOutput/conversationID/iE9F2D01E5EE643ABAD08BB13BB13AA2C
) which will return another similar response if the report is still running, or return the report output, if it is done.
A third option is async=auto
which is asynchronous as well, but returns a redirect http response code (and the redirect url). If your browser or http client respects the redirect, then it will automatically do the polling for you.
------------------------------
Jim Boland
LinkedIn: https://www.linkedin.com/in/jimboland
Website: https://coreinsightz.com
Email: jimboland@coreinsightz.com
Original Message:
Sent: Fri September 29, 2023 10:35 AM
From: SRIHARI CHANDRAMOULI
Subject: Python Cognos Analytics with REST API
Thanks a lot Jim, the mashup url worked perfectly. I was able to run the report in a PDF Format. I was able to get the conversation ID in this format:
https://my-server/ibmcognos/bi/v1/disp/rds/sessionOutput/conversationID/iDF7DE2EB6B7045DF9038D3159F9CE3F6
Now, i want to retrieve/download the report using REST APIs. I guess we would need to use the conversationID right for this purpose?
------------------------------
SRIHARI CHANDRAMOULI
Original Message:
Sent: Thu September 28, 2023 10:28 PM
From: Jim Boland
Subject: Python Cognos Analytics with REST API
Hi Srihari,
Sorry, that was my fault - I had just copy/pasted the prompt stuff incorrectly in the example in my reply above. I've edited/fixed up the example in that comment, now.
For CMS, you have two options for how you specify the prompt parameters
- long-form - add an xmlData query parameter to your url, containing a <promptAnswers> xml element. Details/example here
- shorthand - add a p_<prompt_parameter_name>=<prompt_value> query parameter for each prompt. Details of how you can specify more complicated things in the values (e.g. ranges) are here
Here's an example (that I tested before posting this time! 😎):
https://us3.ca.analytics.ibm.com/bi/v1/disp/rds/outputFormat/report/i15E936FAE97A43AE88385CADB5B7807E/PDF?p_product=Earl%20Grey&p_type=Black%20tea
This example runs the report with storeID i15E936FAE97A43AE88385CADB5B7807E, with the prompt answers:
- product set to "Earl Grey"
- type set to "Black tea"
and returns a PDF format of the resultant report output.
------------------------------
Jim Boland
LinkedIn: https://www.linkedin.com/in/jimboland
Website: https://coreinsightz.com
Email: jimboland@coreinsightz.com
Original Message:
Sent: Thu September 28, 2023 11:32 AM
From: SRIHARI CHANDRAMOULI
Subject: Python Cognos Analytics with REST API
Thanks a lot Jim. The outputFormat resource worked out well. I am able to get the report in a PDF version. However there seems to be some error regarding the passing of my parameters. The returned PDF Report did not have any values.
This is my original URL which does not use mashup and works fine:
https://my-server/ibmcognos/bi/?pathRef=my-report-path&action=run&format=PDF&prompt=false&promptParameters=%5B%7B%22name%22%3A%22client_id%22%2C%22value%22%3A%5B%7B%22use%22%3A%22<client-id>%22%2C%22display%22%3A%22<client-name>%22%7D%5D%7D%5D
And here is the mashed up url:
https://<my-server>/ibmcognos/bi/v1/disp/rds/outputFormat/report/iD9493B2B788C40B7BFD20C92888EE745/PDF&p_client_id=<selectChoices><selectOption useValue="client_id" displayValue="client_name"/></selectChoices>
I was not able to find anything about formatting parameters. But if you could give me some insights, it would be great. Thank you for helping me out.
------------------------------
SRIHARI CHANDRAMOULI
Original Message:
Sent: Thu September 28, 2023 09:04 AM
From: Jim Boland
Subject: Python Cognos Analytics with REST API
Hi Srihari,
Yes, CMS has two different - somewhat overlapping - RDS resources:
- the reportData resource that you tried has the following formats (i.e. "fmt=") supported :LDX (XML), Simple (XML), HTML, HTML fragment, JSON, DataSet XML/ATOM/JSON, and Image. These formats are NOT the report server formats you can choose in the CA portal. (Instead, they are formats built to facilitate embedding/"mashing-up" report content into another application/environment. (e.g. PDF is NOT one of the fmt supported for this call.)
- the outputFormat resource, on the other hand, runs/returns the report output in one of the formats you can generate in the CA portal (e.g. CSV, MHT, PDF, spreadsheetML, XLWA, XML, xlsxData). This is the REST call, I believe you want to use, for the scenario you described (more details here).
You can specify the specific report, and the prompt parameters in the same way for either of these call (outputFormat or reportData).
E.g. your call probably looks something like:
https://<my-server>/ibmcognos/bi/v1/disp/rds/outputFormat/report/iD9493B2B788C40B7BFD20C92888EE745/PDF&p_client_id=<selectChoices><selectOption useValue="client_id" displayValue="client_name"/></selectChoices>
------------------------------
Jim Boland
LinkedIn: https://www.linkedin.com/in/jimboland
Website: https://coreinsightz.com
Email: jimboland@coreinsightz.com
Original Message:
Sent: Wed September 27, 2023 03:47 PM
From: SRIHARI CHANDRAMOULI
Subject: Python Cognos Analytics with REST API
Thanks a lot Jim. I was able use the REST API option within CMS. However, I want PDF as the format of the returned output. And it looks like "fmt" does not give me an option to export it as PDF
https://www.ibm.com/docs/en/cognos-analytics/11.2.0?topic=options-fmt
So far,
- I was able to use the mashup API to authenticate using auth/logon
- I was able to construct the URL as follows which returned an XML structure when I pasted it in my browser window. Here is the URL:
https://<my-server>/ibmcognos/bi/v1/disp/rds/reportData/report/iD9493B2B788C40B7BFD20C92888EE745?fmt=PDF&p_client_id=<selectChoices><selectOption useValue="client_id" displayValue="client_name"/></selectChoices>
- fmt=HTML works but things look out of place
- I guess I will find out a way to export PDF via REST API?
Any help appreciated
------------------------------
SRIHARI CHANDRAMOULI
Original Message:
Sent: Wed September 27, 2023 04:42 AM
From: Jim Boland
Subject: Python Cognos Analytics with REST API
Hi Srihari,
Yes the "new Cognos REST API" (i.e. https://www.ibm.com/docs/en/cognos-analytics/11.1.0?topic=apis-rest-api ) is mostly focused on automating the administrative operations of CA (e.g. managing users/groups/roles, UI customization like extensions and themes, Content Manager content, datasources/modules, etc.)
Probably more suited to what you are trying to accomplish is the Cognos Mashup Service ( https://www.ibm.com/docs/en/cognos-analytics/11.0.0?topic=guide-developing-mashup-service-applications-using-rest-interface ) - and specifically the REST API option within CMS. With it, you can login into Cognos, run reports (including specifying the parameters for prompted reports). As well if you want the resulting report output returned (as opposed to just run and saved in the CA portal) you can specify the format you want the report results returned in (e.g. image, HTML, HTML fragment, XML, JSON. Or you can ask for the report in one of the report viewer formats (e.g. PDF, Excel, etc.). Unlike the automation of administrative tasks role of the "new REST API", Cognos Mashup service is more a web service to your reports themselves.
Note: if you are looking to actually programmatically consume the results of the report in Python (e.g. pandas), Cognos has created a python module, CADataConnector, to allow you to work with (create and read) CA data resources directly in python, without using reports. CADataConnector is not published by itself, but is included in the IBM Cognos Analytics for Jupyter Notebook Server and in Watson Studio Notebook environment .
------------------------------
Jim Boland
LinkedIn: https://www.linkedin.com/in/jimboland
Website: https://coreinsightz.com
Email: jimboland@coreinsightz.com
Original Message:
Sent: Mon September 25, 2023 11:25 AM
From: SRIHARI CHANDRAMOULI
Subject: Python Cognos Analytics with REST API
Hey Community and Experts,
I would like to generate Cognos reports using Python. Is this possible at all? I could not find any documentation regd. running of reports programatically. There is Cognos Documentation regarding REST APIs but I could not find anything related to running of Reports.
Here is what my request is:
Does the Cognos API allow us to specify the following:
- which report to run
- with the appropriate parameters for example - customer, time range, etc...
I want to use Python to achieve this.
NOTE: I have used parameterized URLs that will return customized urls. But I want to achieve this via REST APIs and python. Any help appreciated.
#Cognos Analytics with Watson
------------------------------
SRIHARI CHANDRAMOULI
------------------------------