Cognos Analytics

 View Only
Expand all | Collapse all

Can I set up a schedule using the Cognos REST API?

  • 1.  Can I set up a schedule using the Cognos REST API?

    Posted Mon January 23, 2023 01:31 PM
    Hi Team,

    I have quesions about Cognos REST API.

    Can I use the Cognos REST API to do the following operations?
    - Set parameter values in a reportview.
    - Set up a schedule (trigger type schedule)

    Thanks!

    ------------------------------
    TOSHIYA HAYASHI
    ------------------------------


  • 2.  RE: Can I set up a schedule using the Cognos REST API?

    IBM Champion
    Posted Tue January 24, 2023 03:36 AM
    You can do both, but they're not officially supported or even listed in the documentation. I have a method for updating parameters in reports and reportviews already in CogBox, and I just added a copy/paste schedule to it as well. 

    In both cases you need to first get the storeID of the object, the properties of the report will give it to you. It will be a 33 character string beginning in "i"
    iED5A1D764CCB44818AB495DEB659F55C

    With that you can construct the URL you need. 
    var url = gateway + '/v1/objects/'+id

    http://server/ibmcognos/bi/v1/objects/iED5A1D764CCB44818AB495DEB659F55C
    For the parameters you're running a PUT and the schedule it's a POST (unless the schedule already exists).

    The request will look like this:
    fetch("https://SERVER/ibmcognos/bi/v1/objects/iED5A1D764CCB44818AB495DEB659F55C", {
    "headers": {
    "cafcontextid": cafcontext,
    "x-xsrf-token": tokenid
    },
    "body": "{\"parameters\":[{\"name\":\"param1\",\"value\":[{\"type\":\"simpleParmValueItem\",\"display\":\"a\",\"use\":\"a\"}]},{\"name\":\"param2\",\"value\":[{\"type\":\"simpleParmValueItem\",\"display\":\"b\",\"use\":\"b\"},{\"type\":\"simpleParmValueItem\",\"display\":\"c\",\"use\":\"c\"}]}],\"type\":\"report\"}",
    "method": "PUT",
    "mode": "cors",
    "credentials": "include"
    });


    The schedule is similar but a little more complicated. It's a post request. The body object looks like this:
    Object.keys(a)
    (55) ['id', 'type', 'defaultDescription', 'state', 'notification', 'permissions', 'hasChildren', 'hidden', 'selected', 'position', 'searchPath', 'ancestors', 'modificationTime', 'disabled', 'capabilities', 'isDirty', 'options', 'printerSelection', 'optionsKey', 'parameterKey', 'parameters', 'executionPrompt', 'parentRunnable', 'triggerName', 'priority', 'endDate', 'everyNPeriods', 'endType', 'usage', 'scheduleRecurrence', 'periodicalProducer', 'credential', 'currentUserCredential', 'isMyCredentials', 'active', 'monthlyRelativeWeek', 'monthlyRelativeDay', 'monthlyAbsoluteDay', 'scheduleType', 'startDate', 'yearlyRelativeDay', 'yearlyAbsoluteDay', 'yearlyRelativeWeek', 'yearlyAbsoluteMonth', 'yearlyRelativeMonth', 'dailyPeriod', 'scheduleBy', 'weeklySunday', 'weeklyMonday', 'weeklyTuesday', 'weeklyWednesday', 'weeklyThursday', 'weeklyFriday', 'weeklySaturday', 'timeZoneID']

    The easiest way is to create a schedule and use the browser toolbar to see exactly what it's doing:


    Now obviously this is not supported. The official API and documentation can be found here: https://www.ibm.com/docs/en/cognos-analytics/11.2.0?topic=SSEP7J_11.2.0/com.ibm.swg.ba.cognos.ca_api.doc/swagger_ca.json

    Feel free to reach out to me. I specialize in this kind of thing, and depending on what you're looking to do I can add this to cogbox.

    ------------------------------
    Paul Mendelson
    ------------------------------



  • 3.  RE: Can I set up a schedule using the Cognos REST API?

    Posted Tue January 24, 2023 09:25 PM
    Edited by TOSHIYA HAYASHI Tue January 24, 2023 09:25 PM
    Hi Paul,
    Thank you for reply.

    Actually, I'm currently looking into the possibility of using the REST API to perform the following operations in a batch process.

    - Check to see if the report view to be executed already exists
     - If not, copy the report view
     - Rename the copied report view
     - Change the value of a parameter of the copied report view
     - Set a trigger type schedule for the copied report view
    - Fire the trigger and execute the report view
    - Verify that the scheduled report has been successfully saved to the Content Store

    *The report view copies the values specified in the prompt to the key. This makes it easier to find saved reports.

    It seems that this can be done from the information you have already linked to me, but we would like to know how these operations can be accomplished with the REST API.


    ------------------------------
    TOSHIYA HAYASHI
    ------------------------------



  • 4.  RE: Can I set up a schedule using the Cognos REST API?

    Posted Wed January 25, 2023 12:07 AM
    One more additional question.

    Do I need to add "CogBox" as an extension to Cognos to set parameters and schedule report views as I asked above?

    Thank you in advance.

    ------------------------------
    TOSHIYA HAYASHI
    ------------------------------



  • 5.  RE: Can I set up a schedule using the Cognos REST API?

    IBM Champion
    Posted Wed January 25, 2023 05:58 AM
    I would say that you don't need CogBox, it just has a lot of the work you're asking for.

    It also depends greatly on where you're looking to trigger this. One of the controls I've made is a button that will take the report the user has run and save that as a report view with the selected parameters to the user's My Folder. But if you're looking to automate this from outside of Cognos, this absolutely won't help. 

    Regarding your list:
    - Check to see if the report view to be executed already exists
    As long as you have a consistent naming convention, you can do a searchpath query to check if it exists
     - If not, copy the report view
     - Rename the copied report view
     - Change the value of a parameter of the copied report view
    When you're saving the report view, a few things happen. 
    1. The logged in user needs to have permissions to save to the specified folder
    2. When you create the object you'll specify the name and parameter values. 
     - Set a trigger type schedule for the copied report view
    Not a problem, just sniff what happens when you create a schedule for another object and use that as a template

    - Fire the trigger and execute the report view
    A bit more tricky, do you want to run the triggername, which might trigger other schedules as well, or just the schedule of the new object?

    - Verify that the scheduled report has been successfully saved to the Content Store
    Also tricky - you can run the schedule but I haven't found a way to get a notification on success or failure. You'll just have to check the execution history of the object periodically.

    If you want to make this a button that exists in the report, I've done similar things often enough that this should only take a couple days of development. Outside of Cognos, like part of a third party ERP, you'll need to handle authentication and a few other issues.

    ------------------------------
    Paul Mendelson
    ------------------------------



  • 6.  RE: Can I set up a schedule using the Cognos REST API?

    Posted Thu January 26, 2023 08:50 PM
    Thank you for your comment.

    I want to do these things from a Java batch program placed outside of Cognos.

    Can I set parameter values and schedule when I run the REST API from a Java batch?

    ------------------------------
    TOSHIYA HAYASHI
    ------------------------------



  • 7.  RE: Can I set up a schedule using the Cognos REST API?

    IBM Champion
    Posted Fri January 27, 2023 07:27 AM
    When connecting through Java you'll need to create a new session with at least read and execute permissions to whatever resources you want to make the report view of, and write permissions to wherever you want to save. https://www.ibm.com/docs/en/cognos-analytics/11.2.0?topic=api-rest-sample

    When making the request you can set the parameters with the following JSON as part of the XMLHttpRequest:

    [{"name": "Country",
    "value": [
    {"use": "1",
    "type": "simpleParmValueItem",
    "inclusive": true,
    "display": "USA"},
    {"use": "2",
    "type": "simpleParmValueItem",
    "inclusive": true,
    "display": "Canada"}
    ]}]


    ------------------------------
    Paul Mendelson
    ------------------------------



  • 8.  RE: Can I set up a schedule using the Cognos REST API?

    Posted Mon January 30, 2023 12:31 AM
    Thank you for your answer.
    But I am really sorry. My question was not a good one.

    My question was not how to set parameters at report view runtime.
    It is the way to store the parameter values in "Current values" in the Report TAB of the properties of the reportview.


    We can save the executed report in the Content Store by doing a scheduled run. (*We are aware that HTTP access from JAVA to run a report does not allow us to save an executed report in the Cotent Store).

    Having a report view for each parameter value in the same report definition would make it easier for end users to retrieve the executed reports they need.
    Therefore, I need to create a report view, save the parameter values, and then run it on a schedule. I would like to achieve this task with a JAVA program.

    ------------------------------
    TOSHIYA HAYASHI
    ------------------------------



  • 9.  RE: Can I set up a schedule using the Cognos REST API?

    Posted Tue January 31, 2023 09:00 AM
    Edited by Andrew Stalker Tue January 31, 2023 09:14 AM
    Hayashi-San,
      There are certainly advantages to both Report Views and REST API but some thoughts on possible alternatives in case helpful:

    #1 Cognos Bursting
    In case you're not aware of it and have not ruled it out, the Cognos Bursting feature (link below) allows a report author to achieve a result similar to what you're describing and may prove helpful. For one report that has bursting enabled, that report can be scheduled to run and create multiple report outputs - a separate report output (with or without security applied so that only certain users see certain data) for each of a range in parameter/filter values (for example a region report might be burst to create a saved output for each region such that regional staff can access reports with their data.
    These burst saved outputs can be emailed to users and/or users can access the output in the portal underneath the report - as mentioned either with or without security applied so that users only see the saved outputs relevant to them.

    Bursting works well when:
    - The requirement is only to burst on one or at most a few parameters but it not practical when the requirement involves a large number of parameters.
    - The scheduling requirement can be satisfied by regular large bursts (eg daily, weekly, monthly-type regularity) as opposed to fine grain ad hoc frequency.
    - It's beneficial to burst to the full range of parameter values.
    - For scalability, break large parameter ranges into smaller chunks (eg rather than burst an employee report in one go to 30,000 saved outputs, instead do scheduled burst runs in smaller batches eg 50 at a time).

    Enabling Bursting in a report requires some changes by a report author but is a very powerful Cognos feature.

    DOC: Set Burst Options
    https://www.ibm.com/docs/en/cognos-analytics/11.2.0?topic=reports-set-burst-options

    #2 Cognos SDK Java SOAP Samples
    Otherwise, I wanted to also highlight that if your goal is to use Java rather than JavaScript and you don't mind using SOAP rather than REST API then you'll likely want to have a look at the Cognos JAVA SDK examples that come bundled with Cognos (location below). There's not one single code sample (that I'm aware of) that does all of what you've described but there are samples on creating reports (ReportAdd), applying parameters (ReportParams) and scheduling (Scheduler). 
    NOTE: These are SOAP not REST API but is a supported way that can be used to achieve your described requirements.

    You'll find the SDK samples <cognos_install>/sdk/java/*

    See also the SDK Developer Guide documentation - for example - here's the documentation on creating a schedule in Java:
    https://www.ibm.com/docs/en/cognos-analytics/11.2.0?topic=examples-example-schedule-report

    Cheers,
    Andrew


    ------------------------------
    Andrew Stalker
    ------------------------------



  • 10.  RE: Can I set up a schedule using the Cognos REST API?

    Posted Wed February 01, 2023 08:57 PM
    Thank you for your comment.

    Exactly!
    I believe that if I can't do it with the Java REST API then I have to use the Cognos Java SDK.
    And, as you advised, I assume that the Cognos Java SDK can probably make it happen.
    One of my concerns is that the Java 8 support used by the Cognos Java SDK will end in a few years, so if you have disclosed a roadmap for the Cognos SDK after Java 8 support expires, could you please let me know?


    I understand that burst reporting is one effective way to do this.
    However, I recognize that with burst reports, a report is always created for the value of the item set as the burst key.
    Even if only one report is really needed, if there are 10 values, 10 reports will be created.
    In the case of burst reports that are run daily, the number of unnecessary reports would be too large.

    Thank you.

    ------------------------------
    TOSHIYA HAYASHI
    ------------------------------



  • 11.  RE: Can I set up a schedule using the Cognos REST API?

    Posted Mon February 06, 2023 06:31 AM
    Hi Andrew,

    I just want to confirm one thing since a team member is concerned about it.

    Regarding the three processes you described, if it can be done with SOAP, wouldn't it be possible to achieve it with a REST API?
    Is it not possible to achieve this with the REST API?

    ・creating reports (ReportAdd)
    ・applying parameters (ReportParams)
    ・scheduling (Scheduler)

    ------------------------------
    TOSHIYA HAYASHI
    ------------------------------



  • 12.  RE: Can I set up a schedule using the Cognos REST API?

    IBM Champion
    Posted Tue February 07, 2023 05:32 AM
    I do want to assure you that everything you're asking for is possible. I recommend using the developer toolbar and monitoring the network tab to see exactly how Cognos does it. Just write your application around what you see.

    Creating a report:
    Post request: GATEWAY/bi/v1/reports
    http://localhost/ibmcognos/bi/v1/reports

    Creating a schedule:
    Post request: GATEWAY/bi/v1/admin/objects/<OBJECT STORE ID>/items
    http://localhost/ibmcognos/bi/v1/admin/objects/i7B660E4D1C664504A9C951DDBB978DCE/items

    applying parameters:
    PUT request: GATEWAY/bi/v1/objects/<OBJECT STORE ID>
    http://localhost/ibmcognos/bi/v1/objects/i7B660E4D1C664504A9C951DDBB978DCE

    Feel free to contact me directly and I'll be able to help you more.

    ------------------------------
    Paul Mendelson
    ------------------------------



  • 13.  RE: Can I set up a schedule using the Cognos REST API?

    Posted Wed February 08, 2023 10:05 AM
    Hi Paul.

    Thank you for your comment.
    In the example you showed, it looks like you are using /bi for the endpoint.
    <Gateway>/bi/v1/...

    I assumed the endpoint would be /api/v1 since it is intended to run within a JAVA program.

    Can I use /bi as an endpoint in my java program?As a test, I tried accessing /bi using the curl command at the command prompt, but was unable to create a session or perform any subsequent processing.


    ------------------------------
    Yuki Ogihara
    ------------------------------



  • 14.  RE: Can I set up a schedule using the Cognos REST API?

    IBM Champion
    Posted Thu February 09, 2023 05:05 AM

    Hey Yuki, You're absolutely correct, The /bi is actually part of the gateway. In my code for the extensions I use (as an example):

    let url = `${__glassAppController.glassContext.gateway}/v1/objects/${storeId}/items?fields=*` 

    That gets the children, and all of the fields, of the given object. I recommend against using fields=*, instead focusing only on the fields you actually need. Pulling everything can take a very long time.



    ------------------------------
    Paul Mendelson
    ------------------------------



  • 15.  RE: Can I set up a schedule using the Cognos REST API?

    Posted Fri February 24, 2023 05:44 AM
    Edited by Bek Ibragimov Fri February 24, 2023 06:18 AM

    Hello Paul, 

    Is it possible to disable/enable the schedule of report via API endpoint. I was able to connect to Cognos server and get items of report using Gateway/v1/content/<OBJECT ID>/items. From there I took scheduleID value and used here Gateway/v1/content/<SCHEDULE ID>/items, but this didn't give any result. If you can give any suggestions about this, that would be great.

    $headers = @{
        "IBM-BA-Authorization" = "Generated_API_KEY"
        "Content-Type" = "application/json"
    }
     
    $body = "{
    `n    `"parameters`": [
    `n        {
    `n            `"name`": `"CAMNamespace`",
    `n            `"value`": `"<Our_Namespace>`"
    `n        },
    `n        {
    `n            `"name`": `"CAMUsername`",
    `n            `"value`": `"<UserName>`"
    `n        },
    `n        {
    `n            `"name`": `"CAMPassword`",
    `n            `"value`": `"<Password>`"
    `n        }
    `n    ]
    `n}'"
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
    $response = Invoke-RestMethod 'https://<cognos_server_url>/api/v1/session' -Method 'PUT' -Headers $headers -Body $body
    $response | ConvertTo-Json
     
    $NewAuthorization=$response.session_key
     
     
    $newheaders = @{
        "IBM-BA-Authorization" = "$NewAuthorization"
        "Content-Type" = "application/json"
    }
     
    $response1 = Invoke-RestMethod 'https://<cognos_server_url>/api/v1/content/<ScheduleID>/items' -Method 'GET' -Headers $newheaders
    $response1 | ConvertTo-Json
     
    Write-Host $response1

    Thank you

    ------------------------------
    Bek Ibragimov
    ------------------------------



  • 16.  RE: Can I set up a schedule using the Cognos REST API?

    Posted Tue January 31, 2023 05:39 PM
    Dear all

    While executing the report view, is there a paging option in the json file which we define the parameters through the rest api as mentioned below? (E.g. 20 rows in each consequtive requests)

    Regards
    Sukru