“I’d like to share file only to specific external email addresses, not everyone with a link, is that doable in Power Automate flow?”
When sharing files with external users, Power Automate gives quite you limited possibilities. You can either share the file in your organisation, or to everyone with a link. The option to share only with people you choose, the option provided by SharePoint, isn’t there.
Yet that seems to be the more reasonable way of external sharing. Sharing files externally to everyone with a link seems a bit too excessive. Which brings us to the topic of this blog post – how to share files externally only to specific people?
Note: the solution is using Graph API – you’ll need a premium license to use it.
Use Graph API to share the files
Since the SharePoint actions won’t help you, and I didn’t find any useful http request to SharePoint, let’s do it using Graph API. But to use Graph you need more than just SP site url, library name, etc., you need their id’s.
All the actions below are the preauthorized Entra ID ‘Invoke an HTTP request’.
Get the SharePoint site id
The first id is the SharePoint site id. Send an http request where you search for your site among all the sites.
Method: GET
Uri: https://graph.microsoft.com/v1.0/sites?search=<SPsite>
Note: <…> is a placeholder, replace it including the < and >.
With the right search parameter it should return only the specific site. Extract its id with an expression.
first(body('Invoke_an_HTTP_request_-_site_id')?['value'])?['id']
Get the list id
With the site id you can search for the document libraries, called ‘drives’ when using Graph API. Use the request below where you find the library by name.
Method: GET
Uri: https://graph.microsoft.com/v1.0/sites/@{first(body('Invoke_an_HTTP_request_-_site_id')?['value'])?['id']}/drives?$filter=name eq '<libraryName>'
Note: <…> is a placeholder, replace it including the < and >.
Extract the library id to use it in the next request.
first(body('Invoke_an_HTTP_request_-_library_id')?['value'])?['id']
Get the file id
You’ll need also the id for the file as it’s not using the standard SharePoint id. In the example below it’s searching for the file using the file full name.
Method: GET
Uri: https://graph.microsoft.com/v1.0/sites/@{first(body('Invoke_an_HTTP_request_-_site_id')?['value'])?['id']}/drives/@{first(body('Invoke_an_HTTP_request_-_library_id')?['value'])?['id']}/items?$filter=name eq '<fileNameWithExtension>'
Note: <…> is a placeholder, replace it including the < and >.
Again, take the file id from the result.
first(body('Invoke_an_HTTP_request_-_file_id')?['value'])?['id']
Share the file with the email address
Once you have all the information from above, the SP site id, library id and file id, you can finally share it with the fourth http request.
Method: POST
Uri: https://graph.microsoft.com/v1.0/sites/@{first(body('Invoke_an_HTTP_request_-_site_id')?['value'])?['id']}/drives/@{first(body('Invoke_an_HTTP_request_-_library_id')?['value'])?['id']}/items/@{first(body('Invoke_an_HTTP_request_-_file_id')?['value'])?['id']}/invite
Body:
{
"recipients": [
{
"email": "<emailAddress>"
}
],
"message": "<description in the invite>",
"requireSignIn": true,
"sendInvitation": true,
"roles": [
"<write | read>"
]
}
Note: <…> are placeholders, replace it including the < and >.
That’s it, the request will create a sharing link to a file that’ll be accessible only for the specific email address.
Summary
As I said many times before, if Power Automate doesn’t give you what you need, you might need an http request. In this case it’s sharing files only to specific external email addresses. Power Automate let’s you share file only within organisation or to everyone, but with the http requests to Graph API as explained above you can share it only to specific external email address.
It might be a bit more complicated solutions as you work with strange looking id’s, but in the end it’s only 4 http requests to collect all the information to get the job done.