I have a function here that will add actual work hours in MS project server 2013 using REST. However, I keep getting a bad request. I do not know what parameters I have to include or to tweak to get this done. Here is my code.

public async void addTimesheetLineWork() {

        var formDigest = await GetFormDigest();

        var handler = new HttpClientHandler();
        handler.CookieContainer = new CookieContainer();
        handler.CookieContainer.Add(new Cookie("rtFa", rtFa, "/", "sharepointevo.sharepoint.com"));
        handler.CookieContainer.Add(new Cookie("FedAuth", FedAuth, "/", "sharepointevo.sharepoint.com"));

        HttpClient client = new HttpClient(handler);
        var mediaType = new MediaTypeWithQualityHeaderValue("application/json");
        mediaType.Parameters.Add(new NameValueHeaderValue("odata", "verbose"));
        client.DefaultRequestHeaders.Accept.Add(mediaType); ;
        client.DefaultRequestHeaders.Add("X-RequestDigest", formDigest);

        var body = "{'parameters':{'ActualWork':'3h', 'Start':'"+ DateTime.Today.AddDays(-2)+"', 'End':'"+ DateTime.Today + "', 'Comment':'Commented by KFsama', 'NonBillableOvertimeWork':'0h', 'NonBillableWork':'0h', 'OvertimeWork':'0h', 'PlannedWork':'0h'} }";
        var contents = new StringContent(body, Encoding.UTF8, "application/json");


            var postResult = await client.PostAsync(siteUrl + "/sites/mobility/_api/ProjectServer/TimeSheetPeriods('5ce36a28-c90e-e711-80d2-00155d0cbd04')/TimeSheet/Lines('48f127c8-771b-bfce-72b9-a6923390861a')/Work/Add", contents);
            var result = postResult.EnsureSuccessStatusCode();
            if (result.IsSuccessStatusCode)
                Log.Info("Timesheetz add work", "mana og add");

        catch (Exception e)
            Log.Info("Timesheetz add work", "failed kay " + e.Message);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.