web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Using Power Automate t...
Power Automate
Unanswered

Using Power Automate to get File content from a SharePoint URL

(0) ShareShare
ReportReport
Posted on by 12

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. (Originally posted on Stack Overflow)

Categories:
I have the same question (0)
  • Verified answer
    Expiscornovus Profile Picture
    33,183 Most Valuable Professional on at

    Hi @GuyanthalasSEA , 

     

    I also replied to your thread on Stack Overflow, but I will also post it here.

     

    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 the 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))

     

     

    serverrelativeurl_propertyvalue.PNG

     

  • GuyanthalasSEA Profile Picture
    12 on at

    You did, thank you! I was going to post your solution here but glad you are active in both places. Appreciate your help, it is working quite well. I also had not used "slice" before, that will improve a few other things that I'm working on.

  • mloyalka Profile Picture
    28 on at

    Thank you for the solution. From where do u got the cd value to initialize the variable?

  • GuyanthalasSEA Profile Picture
    12 on at

    I'm not sure what your question is. What do you mean by "CD Value"? If you are referring to the sourcedoc value, that is retrieved from the URL itself. 

  • mloyalka Profile Picture
    28 on at

    Thanks for reaching out on this. I was referring to this value 

    mloyalka_0-1682518182638.png

    If it is retrieved from URL can u tell me how you were able to retrieve it . Even I am working with URL in the format  

    "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"

  • GuyanthalasSEA Profile Picture
    12 on at

    You isolate the sourcedoc guid using a combination of split and substring. 

    substring(split(triggerBody()['text'],'sourcedoc=%7B')[1],0,36)

     

    The URL in my case always contains the "sourcedoc=%7B" and is immediately followed by the GUID I need for the http request. Hopefully that helps!

  • mloyalka Profile Picture
    28 on at

    thanks for the help with this. I will run some test on this

  • Vaibhav_k Profile Picture
    on at

    Hi @Expiscornovus, I am having similar requirement. I am unable to generate the complex  URL that sharepoint generates when trying to open the file. How can I get the file url?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 523 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 406 Moderator

#3
abm abm Profile Picture

abm abm 245 Most Valuable Professional

Last 30 days Overall leaderboard