I am trying to retrieve data from P6 EPPM API following their documentation as per https://docs.oracle.com/cd/F51301_01/English/Integration_Documentation/rest_api/index.html
I am using PySpark in Microsoft Fabric as I need to ingest the data to data warehouse. I have got P6 Cloud login with admin access and API license however when I was trying to call the REST API, it keeps throwing response 401 error.
My code is as per below:
import requests
def getAccessToken():
username = 'XXXXXX'
password = 'XXXXX'
credentials = f"{username}:{password}"
b64_credentials = base64.b64encode(credentials.encode()).decode()
headers = {'token_exp':'3600','authToken': b64_credentials}
url = 'https://XXXXX/p6ws/oauth/token'
response = requests.post(url, headers=headers)
api_response = response.content.decode('UTF-8')
accesstoken = api_response.replace('n','')
return (accesstoken)
def getDataFromP6eppm():
headersAPI = {'Content-Type': 'application/json',
'Authorization': 'Bearer ' + getAccessToken()
}
response = requests.get('https://XXXXX/p6ws/restapi/project?',headers = headersAPI)
return(response)
getDataFromP6eppm()
The first function getAccessToken() has connected successfully with response[200] however getDataFromP6eppm() doesnt like it with 401 response, anyone could help?
Tong LIU is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.