Cognos Analytics

Cognos Analytics

Connect, learn, and share with thousands of IBM Cognos Analytics users! 

 View Only
  • 1.  Handling Large Number of Groups in REST API Requests on Cognos Analytics with Watson 11.2.0

    Posted Fri March 08, 2024 10:35 AM

    Hello!

    I've been working with the REST API on Cognos Analytics 11.2.0 to retrieve groups from a specific folder. While the API call succeeds, it seems to cap the response at 100 groups, which is problematic when dealing with folders that contain more.

    In version 12.0.0, the pagination is manageable with the 'page' query parameter. However, this parameter doesn't appear to exist in 11.2.0. I've reviewed the documentation but couldn't find a clear method for pagination in this version.

    Here the page query param is available
    On the 11.2.0 (The version I'm currently using), this param doesn't exists.

    Has anyone faced a similar problem, or can someone advise on how to handle larger sets of groups via the API? Are there alternative query parameters or configuration settings that I could use to paginate or retrieve the full list of groups?

    Any insights or guidance would be greatly appreciated!

    #CognosAnalyticswithWatson #GlobalBusinessAnalytics



    ------------------------------
    Guillem Labòria Soto
    ------------------------------


  • 2.  RE: Handling Large Number of Groups in REST API Requests on Cognos Analytics with Watson 11.2.0

    Posted Sun March 10, 2024 05:08 AM

    Hi Guillem,

    For groups to retrive from the Cognos using REST API has limitations in the version prior to 12.0.0, in order to work with the same, need to do a version upgrade.

    We faced the similar issue of limiting only 100 users retrival on the older versions.

    So 11.2.0 would not have these pagination parameters and 100 is a limit.

    Jacky



    ------------------------------
    Jacky Patel
    Director Analytics Solutions
    Veracitiz Solutions Pvt Ltd
    Navi Mumbai
    +919167755646
    ------------------------------



  • 3.  RE: Handling Large Number of Groups in REST API Requests on Cognos Analytics with Watson 11.2.0

    Posted Tue March 12, 2024 03:39 AM

    It took me a long time to figure this one out. If you're willing to use some undocumented APIs, you can use the expressbus/content-manager API. This lets you search by searchpath, and is the base of many of my tools. 

    Take a look at this example.

    http://server/bi/v1/expressbus/content-manager?searchPath=//role|//group&properties=defaultName,id,searchPath,parent,ancestors,creationTime,modificationTime,type,defaultDescription,owner,members,userProfileSettings&options={maxObjects:100,skipObjects:100}

    1. http://server/bi/ - gateway
    2. v1/expressbus/content-manager - API
    3. ?searchPath=//role|//group - Searchpath.
      If you want to look in a specific folder you can do //folder[@name="folder name"]//role or storeId("i1234")//role searchpath is essentially an xpath expression, so folder//role will recursively pull every role under the folder. If you want only the children of the folder you'd do folder/role the pipe (|) is an OR clause. storeId("i1234")//role|storeId("i1234")//group means it will pull all of the roles and groups under the i1234 object. 
    4. &properties=defaultName,id,searchPath,parent,ancestors,creationTime,modificationTime,type,defaultDescription,owner,members,userProfileSettings
      This refers to the individual fields available the type. 
      Available fields are:
      1. _meta
      2. ancestors
      3. camIdentity
      4. creationTime
      5. defaultDescription
      6. defaultName
      7. defaultScreenTip
      8. description
      9. disabled
      10. displaySequence
      11. distributionMembers
      12. extensions
      13. governors
      14. hasChildren
      15. hidden
      16. iconURI
      17. id
      18. members
      19. modificationTime
      20. name
      21. options
      22. owner
      23. parent
      24. permissions
      25. position
      26. profileRank
      27. routingHints
      28. screenTip
      29. searchPath
      30. searchPathForURL
      31. securityMembers
      32. shown
      33. tenantID
      34. type
      35. usage
      36. userProfileSettings
      37. version
      38. viewed
    5. &options={maxObjects:100,skipObjects:100}
      There are more options, but these are the ones that are most applicable to what you're asking. maxObjects:100,skipObjects:100 means this will return the second group of 100 roles and groups.

    Out of curiosity, what are you trying to accomplish? If this is something that more people might need I can add it to my tools.



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



  • 4.  RE: Handling Large Number of Groups in REST API Requests on Cognos Analytics with Watson 11.2.0

    Posted Tue March 12, 2024 05:03 AM
    Edited by Guillem Labòria Soto Tue March 12, 2024 05:10 AM

    Thanks for the reply! I'll test it right now.

    As of your question, I want to automate the process that consist on assigning users to groups on IBM Cognos Analytics.

    Right now, the way we create groups and assign users to it is manually done, so the way we would like to automate this process is the next (in this case I'm using an IBM DEMO remote machine):

    1. We recieve two columns in a csv file: Users and Groups. The columns are next to each other, which is by relationate the users with their desired group.
    2. With a script I created with Python we get the groups from the csv file, and we check if they exists in Cognos Analytics with GET ibmdemos:9300/api/v1/groups?parent_id=xOg__ (here's where I found out the problem where if there's more than 100 users, I cannot compare all the existing groups with the csv file groups). The groups are retrieved from a namespace called Cognos.
    3. After the creation of the groups (if necessary) then we assign the users to the groups they belong to based on the CSV structure.

    This is an aproach that I did and may not be the perfect, so if you know any other aproach for accomplish this, I would kindly take the recommendations.



    ------------------------------
    Guillem Labòria Soto
    ------------------------------



  • 5.  RE: Handling Large Number of Groups in REST API Requests on Cognos Analytics with Watson 11.2.0

    Posted Tue March 26, 2024 02:52 PM

    Hello @Guillem Labòria Soto,

    we have been using Cognos SDK to add users to groups based on XML file:

    See source code: https://github.com/AMVARA-CONSULTING/cocoma

    It uses java and runs on command line. We also use it to autodeploy and backup content, setting security, removing content, updating dispatchers, datasources and so on.

    Hope this helps.

    Cheers,

    Ralf



    ------------------------------
    Ralf Roeber
    https://linkedin.com/in/ralf-roeber/
    ------------------------------



  • 6.  RE: Handling Large Number of Groups in REST API Requests on Cognos Analytics with Watson 11.2.0

    Posted Tue March 12, 2024 07:06 AM

    I've been trying to do what you told me but I've found some problems with it.

    How do you authenticate using this API? With the REST API, it is easy with the request PUT and adding to the base url "/session" and the credentials in the body json, but I couldn't find out how to authenticate with this API.



    ------------------------------
    Guillem Labòria Soto
    ------------------------------



  • 7.  RE: Handling Large Number of Groups in REST API Requests on Cognos Analytics with Watson 11.2.0

    Posted Sun March 17, 2024 07:04 AM

    In the response from the session API you should get an XSRF token and a cam_passport. 

    this is from my python script:

            # Make the POST request
            post_response = requests.post(login_url, json=request_body, headers=headers, cookies=get_response.cookies)
     
            # Check the response
            if post_response.status_code == 200:
                cam_passport = post_response.cookies.get('cam_passport', '')
                usersessionid = post_response.cookies.get('cam_passport', '')
                print("xsrf: ", xsrf_token)
                print("cam passport: ", usersessionid)
                pcookies = {
                    "XSRF-TOKEN":xsrf_token,
                    "cam_passport": cam_passport,
                    "usersessionid":usersessionid
                    
                }
                
                headers = {
                    "accept": "application/json, text/javascript, */*; q=0.01",
                    "accept-language": "en-US,en;q=0.9",
                    "x-xsrf-token": xsrf_token,
                    "cam_passport": cam_passport,
                    "usersessionid":usersessionid
                }
                    
                return {"response":post_response.json(),"headers":headers,"cookies":pcookies,"api_url":api_url}
     
    and in the module for actually fetching the data:
    async def get_items_in_stages(url, headers, cookies, options={}, batch_size=100, next_run_callback=lambda x: None, final_callback=lambda x: None):
        skip_objects = 0
        all_records = []
     
        async def fetch_and_process():
            nonlocal skip_objects, all_records
     
            # Modify options with batch_size and skip_objects
            new_options = {**options, 'maxObjects': batch_size, 'skipObjects': skip_objects}
            new_url = f"{url}&{urlencode({'options': str(new_options)})}"
     
            # Fetch data
            data = await get_items(new_url, headers, cookies)



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



  • 8.  RE: Handling Large Number of Groups in REST API Requests on Cognos Analytics with Watson 11.2.0

    Posted Tue May 28, 2024 08:25 AM

    Hello!

    Thanks for the reply and sorry for the wait. I've been trying to use the undocumented API you told me about, but I still have some problems that I don't know how to resolve.

    This is my code for authenticating to the API:

    import requests
    from requests.exceptions import RequestException
    
    def authenticate(base_url, namespace, username, password):
        try:
            session = requests.Session()
            auth_payload = {
                "parameters": [
                    {"name": "CAMNamespace", "value": namespace},
                    {"name": "CAMUsername", "value": username},
                    {"name": "CAMPassword", "value": password},
                    {"name": "h_CAM_action", "value": "logonAs"}
                ]
            }
            
            get_url = f"{base_url}/bi/"
            get_response = session.get(get_url)
            get_response.raise_for_status()
            xsrf_token = get_response.cookies.get('XSRF-TOKEN')
            print(f"XSRF-TOKEN: {xsrf_token}")
    
            post_url = f"{base_url}/bi/v1/login"
    
            post_response = session.post(post_url, json=auth_payload, headers={'X-XSRF-TOKEN': xsrf_token})
            post_response.raise_for_status()
    
            # Extract cookies
            cam_passport = post_response.cookies.get('cam_passport')
            usersessionid = post_response.cookies.get('usersessionid')
            print(f"cam_passport: {cam_passport}")
            print(f"usersessionid: {usersessionid}")
    
            pCookies = {
                "XSRF-TOKEN": xsrf_token,
                "cam_passport": cam_passport,
                "usersessionid": usersessionid
            }
    
            headers = {
                "accept": "application/json,text/javascript,*/*;q=0.01",
                "accept-language": "en-US,en;q=0.9",
                "x-xsrf-token": xsrf_token,
                "cam_passport": cam_passport,
                "usersessionid": usersessionid
            }
    
            return session, headers, pCookies
        except RequestException as e:
            raise ValueError(f"Failed to authenticate: {e}")
    

    It retrieves the XSRF-TOKEN, cam_passport, and usersessionid successfully, but I can't get to use the API when I make a request to http://server:port/bi/v1/expressbus/content-manager. I get a 500 error.

    This is the code I used when making HTTP calls:

    def perform_request(session, method, url, headers, cookies, params=None, data=None):
        try:
            print(f"Request URL: {url}")
            print(f"Request Headers: {headers}")
            print(f"Request Params: {params}")
            print(f"Request Data: {data}")
            print(f"Request Cookies: {cookies}")
    
            if method == 'GET':
                response = session.get(url, headers=headers, params=params, cookies=cookies)
            elif method == 'POST':
                response = session.post(url, headers=headers, params=params, json=data, cookies=cookies)
            elif method == 'PUT':
                response = session.put(url, headers=headers, params=params, json=data, cookies=cookies)
            elif method == 'DELETE':
                response = session.delete(url, headers=headers, params=params, cookies=cookies)
            else:
                raise ValueError(f"Unsupported HTTP method: {method}")
    
            response.raise_for_status()
            return response
        except RequestException as e:
            print(f"Failed to execute request: {e}")
            return None

    If I am doing something wrong, please let me know. Thank you!



    ------------------------------
    Guillem Labòria Soto
    ------------------------------