Original Message:
Sent: Thu June 13, 2024 04:33 AM
From: Gautier DUMAS
Subject: ReportData using CMS Rest Interface
Hi,
in a web service project like this, if you have the possibility of accessing the REST endpoints of your CMS from the LAN, I invite you to first test the different routes indicated from a tool like Postman.
This may initially identify whether the problem is on the REST server or on your client developed in python.
Once you have successfully made the calls that work in Postman (or equivalent tool), we can dig into the calls made in Python. Depending on the server, you may have to call the service not with localhost (even if you are local between the Python script and the REST interface) but with the IP address or domain name of the IBM i which hosts your CMS.
Best regards,
------------------------------
Gautier Dumas
------------------------------
------------------------------
Gautier DUMAS
Original Message:
Sent: Wed June 12, 2024 03:29 AM
From: Sachin Sehrawat
Subject: ReportData using CMS Rest Interface
Hi All,
I'm trying to get report data using the CMS REST Interface. I'm successfully able to log in but I'm getting a 403 Forbidden error while trying to retrieve the report data.
Steps I'm following:
- Using Python's
requests
library to make the REST API call. - Getting the XSRF token from the response of the login, which is done by making a POST call to the URL:
http://localhost:9300/bi/v1/disp/rds/auth/logon?xmlData=<credentials/>
and passing the NameSpace, UserName, and Password in the credentials in XML format. - Passing the XSRF-TOKEN and cookies set in the header while making a GET call to the URL:
http://localhost:9300/bi/v1/disp/rds/pagedReportData/report/i8CDBF4955F594C1FB06FA7BF3CA7D95D?v=1
. - In response, getting a 403 status code.
Here's a snippet of my code for reference:
import requestsdef authenticate(credentials): nameSpace = credentials['NameSpace'] userName = credentials['UserName'] userPassword = credentials['Password'] xmlData = f""" <credentials> <credentialElements> <name>CAMNamespace</name> <label>Namespace:</label> <value><actualValue>{nameSpace}</actualValue></value> </credentialElements> <credentialElements> <name>CAMUsername</name> <label>User ID:</label> <value><actualValue>{userName}</actualValue></value> </credentialElements> <credentialElements> <name>CAMPassword</name> <label>Password:</label> <value><actualValue>{userPassword}</actualValue></value> </credentialElements> </credentials> """ try: login_url = "http://localhost:9300/bi/v1/disp/rds/auth/logon?xmlData=<credentials/>" login_response = requests.post(login_url, data=xmlData) if login_response.status_code == 200: print("Login successful!") print(f"Login Text: {login_response.content}") cookies_ = login_response.cookies login_token = login_response.cookies.get("XSRF-TOKEN") else: print(f"Logon failed. Status code: {login_response.status_code}") except Exception as e: print(f"Error occurs when doing logon: {e}") if login_token: return login_token, cookies_ else: return None,Nonelogin_token, cookies = authenticate(login_credentials)if login_token: report_url = "http://localhost:9300/bi/v1/disp/rds/pagedReportData/report/i8CDBF4955F594C1FB06FA7BF3CA7D95D?v=1" header = { "x-xsrf-token": f"{login_token}", "Content-Type": "application/json" } report_response = requests.get(report_url, headers = header, cookies = cookies) if report_response.status_code == 200: print("Successful!")
Despite following these steps, I still receive a 403 Forbidden error when attempting to access the report data. I have verified that the credentials are correct and the user has the necessary permissions.
Could someone help me identify what might be causing this issue and how to resolve it?
Kindly help me in resolving this issue.
Thank you!
------------------------------
Sachin Sehrawat
------------------------------