cancel
Showing results for 
Search instead for 
Did you mean: 

Create sharing link for a file or folder in SharePoint for specific people

Hi,

 

Currently in the Microsoft Flow 'Create sharing link for a file or folder' the Link Scope field only has the following options:

- Anyone with the link, including anonymous

- People in your organization

 

Please also add the following option which is available in SharePoint and OneDrive:

- Specific people

 

We really need to be able to create a sharing link just for specific people.

Status: New
Comments
Regular Visitor

This depends on the availability of the API in Onedrive and SharePoint.

At the moment, the scope of link to create either anonymous or organization.

Scope types

The following values are allowed for the scope parameter. If the scope parameter is not specified, the default link type for the organization is created.

Value               Description

 

anonymous

Anyone with the link has access, without needing to sign in. This may include people outside of your organization. Anonymous link support may be disabled by an administrator.

organization

Anyone signed into your organization (tenant) can use the link to get access. Only available in OneDrive for Business and SharePoint.

Reference:
https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_createlink?view=odsp-grap...

 

However, with David, you can do the seem-imposible-thing :))) 😀

 

You can use the "Send a HTTP request to Sharepoint" to get a Shareable link to a specified external user

d1agnhm

https://imgur.com/a/HX6bby4

 
  • You need to have List id which is the page where the file is located.
  • Test 01 in the image is the external email to be shared.
  • a1 is the list guid 
  • a2 parameter in the image path is the id of the file: 1
  • example:
  • image.png
  •  
     
    https://imgur.com/MpmME54

 

This is the URi

 

_api/web/Lists(@a1)/GetItemById(@a2)/ShareLink?@a1=%27%7B887C029D%2D25BE%2D467D%2D947C%2DFDF147AD1BA9%7D%27&@a2=%271%27

 

This is the body request for non guest email

 

{
"request":{
"createLink":true,
"settings":{
"linkKind":7,
"expiration":null,
"role":2,
"restrictShareMembership":true,
"updatePassword":false,
"password":""
},
"peoplePickerInput":"[{\"Key\":\"xxx@outlook.com\",\"DisplayText\":\"xxx@outlook.com\",\"IsResolved\":true,\"Description\":\"xxx@outlook.com\",\"EntityType\":\"\",\"EntityData\":{\"SPUserID\":\"xxx@outlook.com\",\"Email\":\"xxx@outlook.com\",\"IsBlocked\":\"False\",\"PrincipalType\":\"UNVALIDATED_EMAIL_ADDRESS\",\"AccountName\":\"xxx@outlook.com\",\"SIPAddress\":\"xxx@outlook.com\",\"IsBlockedOnODB\":\"False\"},\"MultipleMatches\":[],\"ProviderName\":\"\",\"ProviderDisplayName\":\"\"}]",
"emailData":{
"body":"",
"subject":""
}
}
}

 

To parse the output, use Parse Json action

 

4paekg2

 

 

Generate Schema from the Output of Send HTTP request

https://imgur.com/CgkHEjR

CgkHEjR

 

This is sample output

BeB7Y4x

 

Control who can use default "Share" button to share the file with Site sharing settings: Go to a Site => (gear) Settings button on top-right => Site Permissions => Change how member can share

 

Capture2.PNG

 

You should consider some security reasons before sharing a link:

https://docs.microsoft.com/en-us/sharepoint/deploy-file-collaboration#securing-your-data

https://docs.microsoft.com/en-us/sharepoint/modern-experience-sharing-permissions

https://docs.microsoft.com/en-us/sharepoint/turn-external-sharing-on-or-off

https://docs.microsoft.com/en-us/sharepoint/external-sharing-overview

 

Enjoy your works with Microsoft Power Automate!

David Nguyen

 

 

Regular Visitor
Frequent Visitor

Hi @David_Nguyen 

 

Thanks - that looks pretty awesome! Just one question - if you want the link to expire automatically 7 days after being generated, do you have to amend the "expiration":null, field? If so, what would the syntax be?

Regular Visitor

@adriaanvw 

You can pass the Universal datetime format: yyyy-MM-ddTHH:mm:ss.fffZ

 

In my flow, I ask the user who triggers the flow to type the number of days for sharing the file, then I add it to the response date from the approval action.

 

addDays(body('Start_an_approval')?['responseDate'],triggerBody()['number'],'yyyy-MM-ddTHH:mm:ss.fffZ')

 

Capture1.PNG

 

Capture5.PNG

 

About the LinkKind and other settings, review this article:

 

https://docs.microsoft.com/en-us/dotnet/api/microsoft.sharepoint.client.sharinglinkkind?view=sharepo...

 

Good luck!

David Nguyen

 

 

 

 

 

Microsoft

@adriaanvw 

The body request you need to make sure your changes will not break the Json format. If not, there will be the error message like not well-formed Json format.

Frequent Visitor

@David_Nguyen 

 

Thanks again - will give this a try

Frequent Visitor

@David_Nguyen 

 

Thanks - I've made good progress with this project now. I made a couple of changes - set linkKind to 6 (not sure what 7 does - the documentation doesn't mention that option) and role to 1 (View only), which appear to be working.

 

The only bit where I'm stuck is the expiration date. If I leave it as null, the HTTP request completes fine. But when I try to set a date as per the example, I get this error message:

 

"message": "BadGateway",
    "innerError": {
      "status": 502,
      "message": "String was not recognized as a valid DateTime.

 

The expression I'm using is this:

addDays(utcNow(),+7)

 

Which does appear to generate the correct output when running the flow:

"expiration":"2020-04-06T12:26:31.8123672Z",

 

Any ideas on what type of date format it is looking for?

Microsoft

@adriaanvw 

You should review what I commented:

 

You can pass the Universal datetime format: yyyy-MM-ddTHH:mm:ss.fffZ

 

only fffZ (3 numbers) is accepted.

Frequent Visitor

Thanks again @David_Nguyen 

 

The devil was in the detail! It now "works", using this bit of code for setting the expiration date:

 

formatDateTime(addDays(utcNow(),+7),'yyyy-MM-ddTHH:mm:ss.fffZ')

 

I say it works - the flow runs successfully, but totally ignores the expiration date. I assume this is because the sharing link is not an Anonymous link.

 

Therefore I've added a few more steps which delete the folder and its contents after 7 days, effectively breaking the sharing link and rendering it useless.

Microsoft

Hi @adriaanvw 

I tested once and when I opened the link after the expiration date, it shown nothing.

You can test again with time in the next 5 minutes, then access the link again (if I am not wrong :))) )

Let me know the result.