Forum Discussion

OliverWalter's avatar
OliverWalter
Copper Contributor
Oct 24, 2023

How to Access Project Online Data in Python

Hi all, 

 

I am currently trying to access the data found in Project Online via a Python script. I am able to get the access token but when I try to make a get statement with the access token in the header, I only get unauthorized errors. 

 

I keep getting the error: Error: 401 - {"error_description":"Exception of type 'Microsoft.IdentityModel.Tokens.AudienceUriValidationFailedException' was thrown."}

 

When I google the problem, I get the answer saying that my Graph API is not correctly configured. However, when I try to search for other methods, I get the message that Graph API does not support Project Online. I am pretty confused at this stage whether this is even possible.

 

Any help would be greatly appreciated

 

My Python Code:

from adal import AuthenticationContext
import requests

tenant_id = ''
authority_url = f'https://login.microsoftonline.com/{tenant_id}'
client_id = ''
client_secret = ''


## GET ACCESS TOKEN
context = AuthenticationContext(authority_url)
token = context.acquire_token_with_client_credentials(resource_url, client_id, client_secret)
access_token = token['accessToken']

## MAKE API REQUEST
headers = {
    'Authorization': 'Bearer ' + access_token,
    'Content-Type': 'application/json'
}
response = requests.get(api_url, headers=headers)

if response.status_code == 200:
    data = response.json()
    print(data)
    # Process the data here
else:
    print(f"Error: {response.status_code} - {response.text}")
  • Hello OliverWalter ,

    The Graph API does not include any endpoints for Project Online, you need to call these directly from the PWA site. What you can do though is auth to the Project Online Reporting API via an Azure AD app-  see the post here from Brian - it shows you the Azure AD app - the rest of the post is for ADF so that wont be relevant: https://techcommunity.microsoft.com/t5/project-support-blog/reading-project-online-odata-with-azure-data-factory/ba-p/3616300 

    Paul

    • OliverWalter's avatar
      OliverWalter
      Copper Contributor

      Paul_Mather Thanks for the quick response! 

      I went through the response from Brian but I am still confused as to why my code does not work. I took all the steps In the app registration I gave myself all the necessary permissions. I also get the access token so it has to be something to do with the 'get' request that I am doing wrong...

       

      • Paul_Mather's avatar
        Paul_Mather
        MVP

        Hello OliverWalter ,

        For the Project Online Reporting API, it doesn't support app only auth, you need to pass in a valid user too (username + password), it's user + app auth. The user account used will need a license in PWA and also access to the Reporting API. Maybe it's that?

        Paul

  • Aksh01's avatar
    Aksh01
    Copper Contributor

    OliverWalter 

    If I pursue an online MCA from IGNOU, will I easily get access to online projects? Is it a good option for the future? I learned about IGNOU's online MCA admission but couldn’t find any information about projects and starting a career.

     

Resources