Is it possible to interact with Project Server data from a Project Server server-side event handler?

Copper Contributor

I have MS Project Server running on a SP 2016 on-prem SharePoint farm.


I have set up server side event handlers for the OnPublishing and OnPublished events. Everything is configured correctly for those, I do extensive logging and I know that they are fired at the appropriate times.


My goal is to set a project scoped enterprise custom field from that server side code.

I have tried loading/opening the custom field and specific projects using both the Project Server CSOM (Microsoft.ProjectServer.Client) and by making requests to the REST API using System.Net.Http.HttpClient.


Nothing seems to work. Using the CSOM I get a (403) Forbidden error, and making REST requests gets me a System.UnauthorizedAccessException.


I've tried both with and without using SPSecurity.RunWithElevatedPrivileges. I know that that effectively runs the code as the app pool account, and I explicitly added the app pool service account to the "Administrators for Project Web App" group. I also noticed that there is a "Microsoft Project Server Events" service running in the background, and that service is also using the same account as the app pool, so theoretically adding that account to the Administrators group should give it full control.


So why am I getting these "unauthorized" and "forbidden" errors? How can I access a project and set an enterprise custom field from a server side event handler?


This should be possible, somehow, right? Or is it just completely unallowed and impossible to do?


The only other thing I can think of is that we have switched over from windows auth to claims auth... What do I need to do to use the Project Server CSOM or REST API in a claims-y way?

2 Replies

Hello @DylanCristy ,

Does the user account that you are specifying as part of the auth have edit access to that project you are trying to update? Have you tried running the update code in isolation in a console app etc. Does that auth OK? 


Hi @PaulMather, I added the account as part of the "Administrators for Project Web App" group. Regardless of whether or not that gives them edit access to the project file itself, I think it should give them access to the Enterprise Custom Fields, right? The first thing I was trying in my code was, in CSOM:

var field = projectCtx.CustomFields.GetByGuid(fieldID);

and using REST I was trying to GET /_api/ProjectServer/CustomFields('fieldId')

and neither of those worked. I do think it has something to do with claims auth though, we ended up turning off claims auth in my development environment, and now the CSOM code is working. Not fully, yet, I still have some issues to work out, but I can at least load the custom field and load the project.

Do you have any advice on how to use the CSOM using claims auth?