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 requests
def 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,None
login_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
------------------------------