Hello,
how to read a reporting data from Project Online using C#/CSOM (for example using console application or windows service)?
Authentication to SharePoint and Project Server Online basically works fine, but how to pass cloud-credentials (with onmicrosoft.com account) to the context of OData service?
When trying to read list of project names, the following exception occurs: "Access denied. You do not have permission to perform this action or access this resource."
string onlineURL = "https://nnn.sharepoint.com/sites/PWA"; using (ClientContext clientContext = new ClientContext(onlineURL)) { SecureString passWord = new SecureString(); foreach (char c in "some pwd".ToCharArray()) passWord.AppendChar(c); clientContext.Credentials = new SharePointOnlineCredentials("user@nnn.onmicrosoft.com", passWord); projContext = new PS.ProjectContext(onlineURL); projContext.Credentials = clientContext.Credentials; projContext.Load(projContext.Projects); projContext.ExecuteQuery(); foreach (PS.PublishedProject pubProj in projContext.Projects) // This one works fine this.textBox1.Text += pubProj.Name + "\r\n"; ProjectOData.ReportingData context = new ProjectOData.ReportingData(new Uri(onlineURL + "/_api/ProjectData", UriKind.Absolute)); context.Credentials = clientContext.Credentials; //CredentialCache.DefaultCredentials; var query = from p in context.Projects where p.ProjectStartDate > new DateTime(2013, 1, 1) orderby p.ProjectName select p; // This gives the following error: // Access denied. You do not have permission to perform this action or access this resource. foreach (ProjectOData.Project proj in query) this.textBox1.Text += proj.ProjectName + "\r\n"; }
REST queries like below works directly in IE browser (after logged in the PWA tenant) so am I miss something here?
https://nnn.sharepoint.com/sites/PWA/_api/ProjectData/Projects()?$filter=ProjectStartDate gt datetime'2013-01-01T00:00:00'&$orderby=ProjectName
or
https://nnn.sharepoint.com/sites/PWA/_api/ProjectData/Projects()?$orderby=ProjectName
Thanks,
Ville