Is there any graph api to grant access to externalUserID for sharepoint files[ files shared in teams channel]?

Satyam Yadav 6 Reputation points
2022-11-01T06:09:11.717+00:00

Does /invite API work explicitly for driveItem?

If I want to grant access to an external user for file sharing in the channel, can we use the same /invite API ? because in this case though /invite API returns 200 success but when I try to fetch permissions of that file .....granted user still dosen't have permission.

I have used the below two APIs for granting access to the team's channel file.

https://graph.microsoft.com/v1.0/sites/{site-id}/drive/items/{item-id}/invite

https://graph.microsoft.com/v1.0/shares/{encoded-sharing-url}/permission/grant

but still, the permissions array is not updated with the new user - https://graph.microsoft.com/v1.0/drives/{drive-id}/items/{item-id}/permissions

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,445 questions
{count} vote

2 answers

Sort by: Most helpful
  1. !Daniel Bradley 1,051 Reputation points MVP
    2022-11-01T06:45:06+00:00

    Hi @Satyam Yadav

    You should be able to modify this example:

     POST /me/drive/items/{item-id}/invite  
     Content-type: application/json  
          
     {  
       "recipients": [  
         {  
           "email": "user@externaldomain.com"  
         }  
       ],  
       "message": "Here's the file that we're collaborating on.",  
       "requireSignIn": true,  
       "sendInvitation": true,  
       "roles": [ "write" ]  
     }  
    

    See: https://learn.microsoft.com/en-us/graph/api/driveitem-invite?view=graph-rest-1.0&tabs=http

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".


  2. Srinivasa Rao Darna 6,711 Reputation points Microsoft Vendor
    2022-11-01T09:59:29.417+00:00

    Hi @Satyam Yadav ,

    I tested permission grant, able to add external user existing share link created using /drive/items/{id}/invite.
    Screenshot of grantedToIdentities of a driveItem with only 1 external user.
    255962-image.png

    Using Grant permission able to add another external user, below sample snippet.

    POST https://graph.microsoft.com/v1.0/shares/{encoded-sharing-url}/permission/grant  
    Content-type: application/json  
      
    {  
      "recipients": [  
        {  
          "email": "john@contoso.com"  
        },  
        {  
          "email": "ryan@external.com"  
        }  
      ],  
      "roles": ["read"]  
    }  
    

    Screenshot of my test response body.

    255918-image.png

    It will work with the sharing links that have "scope": "users".

    Hope this helps.
    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".