none
Update project owner in Project online via REST API RRS feed

  • Question

  • Hello.

    For updating project owner I'm using such request:
    POST https://domain.sharepoint.com/sites/SandBox//_api/ProjectServer/Projects('2a45c9f8-3c55-e711-80da-00155d74dd11')/Owner HTTP/1.1 Host: http://domain.sharepoint.com  Connection: keep-alive Content-Length: 327 Origin: https://domain.sharepoint.com 

    X-HTTP-Method: MERGE User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 content-type: application/json;odata=verbose accept: application/json;odata=verbose X-RequestDigest: <digest here> Save-Data: onReferer: https://domain.sharepoint.com/sites/SandBox/Project%20Detail%20Pages/BulkEdit.aspx Accept-Encoding: gzip, deflate, br Accept-Language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7 Cookie: <cookie here> {"__metadata":{"type":"SP.User"},"Id":730,"LoginName":"i:0#.f|membership|user1@email.com","Title":"Amit Khare","Email":"user1@email.com","PrincipalType":1,"IsSiteAdmin":true,"UserId":{"__metadata":{"type":"SP.UserIdInfo"},"NameId":"1003bffda14d0f96","NameIdIssuer":"urn:federation:microsoftonline"}}

    But instead of updating owner, this request updating directly user's information.

    What is the right request? I've tried just POST (without MERGE header), PATCH, PUT - no success.

    P.S. I would like to add some screenshots, but got error Body text cannot contain images or links until we are able to verify your account. How should it be done?

    • Edited by Yaroslav88 Monday, January 15, 2018 5:49 PM
    Monday, January 15, 2018 5:46 PM

Answers

  • Hi,

    seems that something has changed since I used this the last time. The following did work for me a view minutes ago:

    Get UserId (to be used to set owner, value from "Id"):
    GET
    .../sites/pwa/_api/web/siteusers()?$Filter=Title eq '<user>'&$SELECT=Id,LoginName,Title
    
    
    Check out
    POST
    .../sites/pwa/_api/ProjectServer/Projects('<ProjectId>')/CheckOut
    
    
    Set owner (with Id from first request above):
    .../sites/pwa/_api/ProjectServer/Projects('<ProjectId>')/Draft
    PATCH
    Header:
    If-Match: *
    body:
    { "__metadata": { "type": "PS.DraftProject" }, "OwnerId": "<UserId>" }
    
    
    Check owner
    GET
    .../sites/pwa/_api/ProjectServer/Projects('<ProjectId>')/Draft/Owner
    
    
    Publish
    POST
    .../sites/pwa/_api/ProjectServer/Projects('<ProjectId>')/Draft/Publish
    
    
    Check in
    POST
    .../sites/pwa/_api/ProjectServer/Projects('<ProjectId>')/Draft/CheckIn


    Regards
    Barbara


    Friday, May 17, 2019 6:20 AM
    Moderator

All replies

  • Hi,

    I used the following, I think you are just missing to update "Draft":

    - Check-Out
    - <a href="https://xxxx.sharepoint.com/sites/pwa/_api/ProjectServer/Projects('')/Draft/Owner">https://xxxx.sharepoint.com/sites/pwa/_api/ProjectServer/Projects('<ProjectId>')/Draft/Owner
    - X-HTTP-Method MERGE
    - {"__metadata":"type":"SP.User"},"Id":<UserId>,"LoginName":"<UserLogin>","Title":"<UserName>","PrincipalType":1,"Email":"","IsSiteAdmin":true,"UserId":{"__metadata":{"type":"SP.UserIdInfo"},"NameId":"...","NameIdIssuer":"urn:federation:microsoftonline"}}

    Regards
    Barbara

    Sunday, January 21, 2018 9:06 AM
    Moderator
  • Unfortunately, nothing has changed
    Wednesday, February 14, 2018 8:02 AM
  • Hi,

    Have you done a check-out before, a publish and check-in afterwards?

    Barbara

    Wednesday, February 14, 2018 8:08 AM
    Moderator
  • Yes, of course.

    POST /sites/SandBox//_api/ProjectServer/Projects('09b5fe67-3e55-e711-80d1-00155d70a00a')/checkOut() HTTP/1.1

    I see that project is checked out

    Try to update:

    POST /sites/SandBox//_api/ProjectServer/Projects('09b5fe67-3e55-e711-80d1-00155d70a00a')/Draft/Owner HTTP/1.1

    X-HTTP-Method: MERGE

    Publish and check in:

    POST /sites/SandBox//_api/ProjectServer/Projects('09b5fe67-3e55-e711-80d1-00155d70a00a')/Draft/publish(true) HTTP/1.1

    Wednesday, February 14, 2018 9:37 AM
  • Has anyone successfully gotten this to work? 

    If so, please share your experience. 

    Thank you

    Thursday, May 16, 2019 8:59 PM
  • Hi,

    seems that something has changed since I used this the last time. The following did work for me a view minutes ago:

    Get UserId (to be used to set owner, value from "Id"):
    GET
    .../sites/pwa/_api/web/siteusers()?$Filter=Title eq '<user>'&$SELECT=Id,LoginName,Title
    
    
    Check out
    POST
    .../sites/pwa/_api/ProjectServer/Projects('<ProjectId>')/CheckOut
    
    
    Set owner (with Id from first request above):
    .../sites/pwa/_api/ProjectServer/Projects('<ProjectId>')/Draft
    PATCH
    Header:
    If-Match: *
    body:
    { "__metadata": { "type": "PS.DraftProject" }, "OwnerId": "<UserId>" }
    
    
    Check owner
    GET
    .../sites/pwa/_api/ProjectServer/Projects('<ProjectId>')/Draft/Owner
    
    
    Publish
    POST
    .../sites/pwa/_api/ProjectServer/Projects('<ProjectId>')/Draft/Publish
    
    
    Check in
    POST
    .../sites/pwa/_api/ProjectServer/Projects('<ProjectId>')/Draft/CheckIn


    Regards
    Barbara


    Friday, May 17, 2019 6:20 AM
    Moderator
  • Thank you Barbara for responding. for updating owner, are you using:

    _api/ProjectServer/Projects('<ProjectId>')/Draft/ 

    or 

    _api/ProjectServer/Projects('<ProjectId>')/Draft/Owner

    I do not see an "OwnerID" available for update either. 

    Also - for the "<userid>" are you using the user GUID, ID, LoginName, UserID?

    Thank you,

    Chris

    Saturday, May 18, 2019 10:34 PM
  • Hi Chris,

    sorry. When I entered the queries yesterday just as text, only half of it was kept. So I had to edit a few times and seems that something was missing until now. I have just corrected and it looks now complete to me.

    Take "Id" from _api/web/siteusers as OwnerId in body for PATCH.

    Regards
    Barbara


    Barbara Henhapl Blog (English/German) MVP

    Sunday, May 19, 2019 4:02 AM
    Moderator
  • Thank you again. I appreciate your patience and assistance. 

    When I look at _api/ProjectServer/Projects('<ProjectId>')/Draft/  I do not see an "OwnerID" available for update. I see the "Owner" node, which takes you to the SP user record. 

    When I use your method, I get this error: "A value without a type name was found and no expected type is available. When the model is specified, each value in the payload must have a type which can be either specified in the payload, explicitly by the caller or implicitly inferred from the parent value."

    I believe this indicates that the field cannot be found for update. 

    Note - I am using Project Online and have successfully updated many other fields and custom fields. 



    Thank you





    Sunday, May 19, 2019 4:01 PM
  • Hi,

    I thin you missed ""If-Match", "*""

    Here some VBA code working fine in Project connected to Project Online in my case:

    Sub UpdateOwner()
    Dim URL As String
    
    Dim arr_RestResult() As Variant
    
    Const PId = "9ffd9c82-ad73-e911-a2ca-d46d6d80df4e"  'My ProjectId
    
    'Digestvalue
    URL = Profiles.ActiveProfile.Server & "/_api/contextinfo"
    Method = "POST"
    Body = ""
    Index = 0
    DigestValue = ""
    Field = "FormDigestValue"
    arr_RestResult = RestResult(URL, Method, Body, Field, Index, "")
    DigestValue = arr_RestResult(0)
    
    'CheckOut
    URL = Profiles.ActiveProfile.Server & "/_api/ProjectServer/Projects('" & PId & "')/CheckOut"
    Method = "POST"
    Body = ""
    Index = 0
    Field = ""
    arr_RestResult = RestResult(URL, Method, Body, Field, Index, DigestValue)
    
    Stop 'Give some Time to check out
    
    'Change Owner
    URL = Profiles.ActiveProfile.Server & "/_api/ProjectServer/Projects('" & PId & "')/Draft"
    Method = "PATCH"
    Body = "{ '__metadata': { 'type': 'PS.DraftProject' }, 'OwnerId': '35' }"
    Body = Replace(Body, "'", """")
    Index = 0
    Field = ""
    arr_RestResult = RestResult(URL, Method, Body, Field, Index, DigestValue)
    
    'Publish
    URL = Profiles.ActiveProfile.Server & "/_api/ProjectServer/Projects('" & PId & "')/Draft/Publish"
    Method = "POST"
    Body = ""
    Index = 0
    Field = ""
    arr_RestResult = RestResult(URL, Method, Body, Field, Index, DigestValue)
    
    'Check In
    URL = Profiles.ActiveProfile.Server & "/_api/ProjectServer/Projects('" & PId & "')/Draft/CheckIn"
    Method = "POST"
    Body = ""
    Index = 0
    Field = ""
    arr_RestResult = RestResult(URL, Method, Body, Field, Index, DigestValue)
    
    Stop 'give some time to publish and checkin
    
    'get owner
    URL = Profiles.ActiveProfile.Server & "/_api/ProjectServer/Projects('" & PId & "')/Draft/Owner"
    Method = "GET"
    Body = ""
    Body = Replace(Body, "'", """")
    Index = 0
    Field = ""
    arr_RestResult = RestResult(URL, Method, Body, Field, Index, DigestValue)
    
    
    
    End Sub
    
    Function RestResult(ByVal URL As String, _
                        ByVal Method As String, _
                        ByVal Body As String, _
                        ByVal Field As String, _
                        ByVal Index As Integer, _
                        ByVal DigestValue As String _
                        ) As Variant()
    Dim oHTTP As New MSXML2.XMLHTTP60
    Dim objDom As MSXML2.DOMDocument60
    Dim v_Arr(2) As Variant
    
    v_Arr(0) = ""
    v_Arr(1) = ""
    v_Arr(2) = ""
    
    Debug.Print URL
    With oHTTP
        .Open Method, URL, False
        .setRequestHeader "Content-Type", "application/json; odata=verbose"
        .setRequestHeader "Accept", "application/json; odata=verbose"
        .setRequestHeader "Content-Length", "255"
        If DigestValue <> "" Then
            .setRequestHeader "X-RequestDigest", DigestValue
        End If
        If Method = "PATCH" Then
            .setRequestHeader "If-Match", "*"
        End If
        If Body = "" Then
            .send
        Else
            Debug.Print Body
            .send (Body)
        End If
        Debug.Print .responseText
    
    End With
    
    
    If Field = "FormDigestValue" Then
        v_Arr(0) = InStr(1, oHTTP.responseText, Field)
        v_Arr(0) = InStr(v_Arr(0) + 16, oHTTP.responseText, """")
        v_Arr(0) = Mid(oHTTP.responseText, v_Arr(0) + 1, 157)
    End If
    
    v_Arr(1) = oHTTP.Status
    Debug.Print oHTTP.Status
    Debug.Print
    
    RestResult = v_Arr
        
    End Function

    You need to enable reference "Microsoft XML, V6.0" in VBA Editor - Tools - References. (I omitted usage of JsonConverter from GitHub and use the string for digest value to make a quick test easier.)

    Regards
    Barbara


    Barbara Henhapl Blog (English/German) MVP



    Monday, May 20, 2019 9:14 AM
    Moderator
  • Barbara - Thank you so much. This was exactly what I needed. 

    I really appreciate your help. 

     

    Monday, May 20, 2019 12:20 PM
  • Hi, I would just add that odata header is required. I'm using spHttpClient from sharepoint framework and by default it sends odata 4.0 header. With 4.0 header request doesn't work: 

    'odata-version': '3.0',
    Thursday, May 23, 2019 1:56 PM
  • Hi everyone,

    can someone help me on this thread ?

    https://social.technet.microsoft.com/Forums/en-US/ae482ea2-9ca2-433f-87e7-e9e943e684fe/how-to-link-enterpriseresource-with-a-sharepoint-user-using-rest-api-and-javascript?forum=projectonline

    Wednesday, September 11, 2019 2:15 PM