Divyang Agrawal
Divyang Agrawal

Reputation: 43

REST Webservice of Project Server 15

I am trying to create a project in Project Server 2013 using REST Webservices, but I am getting an 403 Forbidden Exception when I try to issue a POST request to the project server. The basic doubt is that "Does Project Server allow POST request to be executed?"

And does the Endpoint URL remain same for GET and POST requests generally as well as for Project Server

Kindly provide some inputs for the same.

The Code is as below :-

    Guid pguid = new Guid();
    string projGuid = pguid.ToString();
    string projName = "Mercedes";
    string startDate = DateTime.Now.ToShortDateString().ToString();


    string URI = "http://ServerName/projectservername/_api/ProjectData/Projects";
    //string URI = "http://ServerName/projectservername/Projects.aspx";
    //string myParameters = "BaselineNumber=0&ProjectId=c34ca0f0-1acd-e211-b2e80155def232b&ProjectName=ProjName;    
    string myParameters = "ProjectId=" + projGuid + "&ProjectName=" + projName +      "&ProjectStartDate="+ startDate;
    using (WebClient wc = new WebClient())
    {
        wc.Credentials = new System.Net.NetworkCredential(username, password, domain);
        wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
        wc.Headers.Add("X-HTTP-Method", "PUT");

        string HtmlResult = wc.UploadString(URI, myParameters);
      //  WebHeaderCollection head = wc.ResponseHeaders;


        Console.WriteLine(HtmlResult);
        Console.WriteLine("Bye");
    }

Upvotes: 3

Views: 700

Answers (1)

Daniel Lesser
Daniel Lesser

Reputation: 211

/_api/ProjectData is a read-only ODATA endpoint from SharePoint/Project Server 2010. It is more convenient in many cases for reporting type queries, but not designed for much more than that. /_api/ProjectServer allows you to perform CRUD operations, or call other Project Server methods such as Submitting to a workflow. Like SharePoint you need to first get a X-Request-Digest token before calling a CUD operation over POST with - /_api/ContextInfo and then call /_api/ProjectServer

Unlike the OData interface for the ProjectData service, which is read-only for reporting, you can do CRUD operations using REST queries with the ProjectServer service.

Upvotes: 2

Related Questions