Guy
Guy

Reputation: 158

Using Power Automate to get File content from SharePoint "sourcedoc" GUID

I have a requirement to grab a file from a SharePoint site and attach it to an email. The end user provides the URL to the file, and power automate handles the rest. Originally I was working with a specific "style" of URL and I was able to correctly parse the URL to get the file content.

Style A: https://XXX.sharepoint.com/:b:/r/sites/XSITE/cos_reviewrequest/ARTS/REQ20039_3F3CF5E3265AED11A76E00155DA3F371/SAMPDQ_20221213.docx?csf=1&web=1&e=hNPWKA

However, I am not able to figure out how to use Power Automate with a different url, Style B.

Style B: https://XXX.sharepoint.com/:w:/r/sites/XSITE/_layouts/15/Doc.aspx?sourcedoc=%7B6E045BAE-6000-41E3-A8B8-EE3751D42F7B%7D&file=SAMPDQ_20221213.docx&action=default&mobileredirect=true

Style A is created using the "Share" or "Copy Link" command within sharepoint. Style B is created when you open an editable file and simply copy the URL from the address bar (which I'm finding is how most end users intuitively grab the link).

With Style A, I can parse the folder structure from the URL directly. This is left out of Style B, so I can't configure any of the Power Automate SharePoint integrations to work correctly. "sourcedoc" is a GUID and I thought I could make some use of that, but apparently that is not the File ID that Power Automate needs to work.

I'm open to any options, including custom REST scripts if I need to be.

Upvotes: 0

Views: 3954

Answers (1)

Expiscornovus
Expiscornovus

Reputation: 1497

You could use the Guid/UniqueId from Style B in a GetFileById method within a Send an HTTP request to SharePoint action. That response should give you details like ServerRelativeUrl property value.

You can use that value in a Get file Content using path (with a slice function expression)

Below is an example

1.Uri for the Send an HTTP request to SharePoint action

_api/web/GetFileById('@{variables('UniqueId')}')

2.Expression which you can use in the File Path field of the Get File Content Using Path action. Uses slice and nthIndexOf functions

slice(outputs('Send_an_HTTP_request_to_SharePoint')?['body']['ServerRelativeUrl'], nthindexOf(outputs('Send_an_HTTP_request_to_SharePoint')?['body']['ServerRelativeUrl'], '/', 3))

enter image description here

Upvotes: 1

Related Questions