Business Analytics Connect, learn and share with over 10000 users across the IBM Business Analytics. Join / Log in
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:
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
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 .
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 PDFhttps://www.ibm.com/docs/en/cognos-analytics/11.2.0?topic=options-fmtSo far,
Yes, CMS has two different - somewhat overlapping - RDS resources:
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:
------------------------------Jim BolandLinkedIn: https://www.linkedin.com/in/jimbolandWebsite: https://coreinsightz.comEmail: email@example.com------------------------------
------------------------------SRIHARI CHANDRAMOULIOriginal Message:Sent: Wed September 27, 2023 04:42 AMFrom: Jim BolandSubject: Python Cognos Analytics with REST API
------------------------------Jim BolandLinkedIn: https://www.linkedin.com/in/jimbolandWebsite: https://coreinsightz.comEmail: firstname.lastname@example.orgOriginal Message:Sent: Mon September 25, 2023 11:25 AMFrom: SRIHARI CHANDRAMOULISubject: 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%5DAnd 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.
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
Here's an example (that I tested before posting this time! 😎):
This example runs the report with storeID i15E936FAE97A43AE88385CADB5B7807E, with the prompt answers:
and returns a PDF format of the re