none
Update Project via REST API RRS feed

  • Question

  • I'm working with Project Server via REST API. I'm tring to retriev projects, change them and then checkout, update, checkin changes.
    All stages work fine except UPDATE
    I'm doing checkout (appWebUrl + "/_api/ProjectServer/Projects('" + key + "')/checkOut()")
    Then appWebUrl + "/_api/ProjectServer/Projects('" + key + "')/Draft/update()"
    Then appWebUrl + "/_api/ProjectServer/Projects('" + key + "')/Draft/publish(true)"

    After publish I'm refreshing projects and see, that nothing changed. Could you please look inside my code and may be you'll find my mistake?

    var appWebUrl = "https://rely-c5f16640dff200.sharepoint.com/sites/SandBox/TaskBoardSharePointApp";
    var formDigestValue = "";
    
    //
    function GetProjects() {
        debugger;
    
        requestExecutor.executeAsync({
            url: appWebUrl + "/_api/contextinfo",
            method: "POST",
            headers: {
                "accept": "application/json;odata=verbose",
                "content-type": "application/json;odata=verbose"
            },
            success: function (response) {
                var responseObj = $.parseJSON(response.body);
    			formDigestValue = responseObj.d.GetContextWebInformation.FormDigestValue;
    			//formDigestValue = "0x16F9E2CC330B859CAF7F0F906E7A4CA7ABEF2F0FCED0A06BBCA25D9E950071CEF16B459DA43FF35624E64A7A0780B9E6D33626C1547AE58448E1F5C205A15DDA,26 Apr 2016 18:52:19 -0000"
            },
            error: function (a, b, c) {
                alert('error');
                window.ProgressBarHide();
            }
        });
    	//
    	// Getting projects via REST requests - works fine
    	//
    }
    
    //
    //Some actions here. Pressing SAVE button -> call UpdateProject(key, newData)
    //
    
    function UpdateProject(key, newData) {
        requestExecutor.executeAsync({
            url: appWebUrl + "/_api/ProjectServer/Projects('" + key + "')/checkOut()",
            method: "POST",
            headers: {
                "accept": "application/json;odata=verbose",
                "content-type": "application/json;odata=verbose",
                "X-RequestDigest": formDigestValue
            },
            success: function (checkOutResponse) {
    			//Checkout works well
                CheckOutProjectSucceeded(checkOutResponse, key, newData);
            },
            error: function (a, b, c) {
                alert('error');
                window.ProgressBarHide();
            }
        });
    }
    
    function CheckOutProjectSucceeded(checkOutResponse, key, newData) {
        var postData = { "__metadata": { "type": "PS.DraftProject" } };
        // $.each(newData, function (name, value) {
            // postData[name] = value;
        // });
    	postData['Name'] = 'OData Update Test';
        postJson = JSON.stringify(postData);
        requestExecutor.executeAsync({
            url: appWebUrl + "/_api/ProjectServer/Projects('" + key + "')/Draft/update()",
            method: "POST",
            headers: {
                "accept": "application/json;odata=verbose",
                "content-type": "application/json;odata=verbose",
                "X-RequestDigest": formDigestValue
            },
            body: postJson,
            success: function (updateResponse) {
                UpdateProjectSucceeded(updateResponse, key);
            },
            error: function (a, b, c) {
                alert('error');
                window.ProgressBarHide();
            }
        });
    }
    
    function UpdateProjectSucceeded(updateResponse, key) {
        requestExecutor.executeAsync({
            url: appWebUrl + "/_api/ProjectServer/Projects('" + key + "')/Draft/publish(true)",
            method: "POST",
            headers: {
                "accept": "application/json;odata=verbose",
                "content-type": "application/json;odata=verbose",
                "X-RequestDigest": formDigestValue
            },
            headers: {
                "X-RequestDigest": formDigestValue
            },
            success: function (checkInResponse) {
    			//Checkin works fine too
                CheckInProjectSucceeded(checkInResponse, key);
            },
            error: function (a, b, c) {
                alert('error');
                window.ProgressBarHide();
            }
        });
    }
    
    function CheckInProjectSucceeded(checkInResponse, key) {
    	//After checkin I'm updating list of projects and see, that data (Name in my case) wasn't changed
        alert('Checked in ' + key);
    }

    Tuesday, April 26, 2016 7:51 PM

Answers

  • Almost two years later we've returned to this project and solution has been found:
    instead of POST data to update(), I'm doing PATCH request to the URL /_api/ProjectServer/Projects('" + key + "')/Draft

    and data is looks like "{"__metadata":{"type":"PS.DraftProject"},"Name":"0003 Alex 1 mod 1"}"

    Then publish(true) will update, publish and check in project.


    • Marked as answer by Yaroslav88 Saturday, January 6, 2018 4:49 PM
    • Edited by Yaroslav88 Saturday, January 6, 2018 4:50 PM
    Saturday, January 6, 2018 4:49 PM

All replies

  • Almost two years later we've returned to this project and solution has been found:
    instead of POST data to update(), I'm doing PATCH request to the URL /_api/ProjectServer/Projects('" + key + "')/Draft

    and data is looks like "{"__metadata":{"type":"PS.DraftProject"},"Name":"0003 Alex 1 mod 1"}"

    Then publish(true) will update, publish and check in project.


    • Marked as answer by Yaroslav88 Saturday, January 6, 2018 4:49 PM
    • Edited by Yaroslav88 Saturday, January 6, 2018 4:50 PM
    Saturday, January 6, 2018 4:49 PM
  • This doesnt work for me ... I am getting a The remote server returned an error: (412) Precondition Failed.
    Thursday, May 3, 2018 11:40 PM
  • I followed above REST API method to update the project. It is not working for me. Is there any other way to update the project custom field without referring to checkout methodology. Above approach throwing error when I do REST API call of checkOut():

    Error code:2130575251

    "The security validation for this page is invalid and might be corrupted. 
    Please use your web browser's Back button to try your operation again.\"}}}"

    Please help. 

    Friday, February 22, 2019 10:12 AM