Sharepoint - update sharing information api

Jackson Smith 41 Reputation points
2022-09-14T07:30:43.76+00:00

Hello, im trying to figure out how to remove specific user from file share with sharepoint rest api

can you please provide the full endpoint, params, and body request to do such thing?

another thing, is it possible to change owner of file if possible can you provide the full endpoint?

thank you!

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,617 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,899 questions
{count} votes

Accepted answer
  1. Tong Zhang_MSFT 9,141 Reputation points
    2022-09-15T06:28:49.47+00:00

    Hi @Jackson Smith ,

    According to my research and testing, you can use the following REST API to remove specific user from item:

     POST https://xxxxx.sharepoint.com/sites/xxx/_api/web/lists/getbytitle('<listName>')/items(<ID>)/roleassignments/removeroleassignment(principalid=<userID>,roleDefId=1073741827)  
    

    To get the user's principal ID, please use the following REST API:

    GET https://xxxxx.sharepoint.com/sites/xxx/_api/web/siteusers/getbyemail('xxx@xxxx.com')   
    

    To get the roledefID , please use the following REST API:

     GET https://xxxxx.sharepoint.com/sites/xxx/_api/web/roledefinitions/getByName('contribute')  
    

    My test result:

    1. Get the user's principal ID:
      241361-01.png
    2. Get the roledefID:
      241304-02.png
    3. Remove specific user from item:
      241268-03.png

    In addition, as far as I know, unfortunately, there is currently no way to change the owner of a file using REST API.

    Hope it can help you. Thanks for you understanding.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



1 additional answer

Sort by: Most helpful
  1. Jackson Smith 41 Reputation points
    2022-09-20T17:17:34.777+00:00

    thanks on the answer but it doesnt work, i get the same responses as you but when i go to check the specific share link - some file -> manage access. i see the user is still get access.
    also this endpoint doesnt work for external users - GET https://xxxxx.sharepoint.com/sites/xxx/_api/web/siteusers/getbyemail('xxx[@](/users/na/?userId=189d14d4-bffd-0003-0000-000000000000).com') get User cannot be found.

    maybe this ep will help to change the invitees - https://learn.microsoft.com/en-us/openspecs/sharepoint_protocols/ms-csomspt/4cb29f91-2c41-44d4-892c-80ee0ea9a0f3
    but i need help how to use it because its not clear from the docs.

    Basically i want to remove invitation under link element -> POST _api/web/lists()/items()/GetSharingInformation

    Thanks alot!

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.