Cognos Analytics

 View Only
Expand all | Collapse all

Python Cognos Analytics with REST API

  • 1.  Python Cognos Analytics with REST API

    Posted Tue September 26, 2023 03:15 PM

    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:

    1. which report to run
    2. 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


  • 2.  RE: Python Cognos Analytics with REST API

    Posted Wed September 27, 2023 04:43 AM

    Hi Srihari,

    Yes the "new Cognos REST API"  (i.e. ) 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 ( ) - 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


  • 3.  RE: Python Cognos Analytics with REST API

    Posted Wed September 27, 2023 03:48 PM

    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

    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


  • 4.  RE: Python Cognos Analytics with REST API

    Posted Thu September 28, 2023 09:04 AM
    Edited by Jim Boland Thu September 28, 2023 09:57 PM

    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:


    Jim Boland


  • 5.  RE: Python Cognos Analytics with REST API

    Posted Thu September 28, 2023 11:33 AM

    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:

    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.


  • 6.  RE: Python Cognos Analytics with REST API

    Posted Thu September 28, 2023 10:29 PM
    Edited by Jim Boland Thu September 28, 2023 10:31 PM

    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

    1. long-form - add an xmlData query parameter to your url, containing a <promptAnswers> xml element. Details/example here
    2. 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! 😎):

    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 re