Skip to main content
Community site session details

Community site session details

Session Id :
Power Automate - Building Flows
Suggested answer

HTTP Request to Sharepoint

(0) ShareShare
ReportReport
Posted on by
Looking for some help from the community on the below as I am an idiot and at a total loss on what I am doing wrong. I am attempting to delete a locked file that I created earlier in my flow following this guide: https://www.matthewdevaney.com/4-solutions-for-excel-file-is-locked-error-in-power-automate/#Solution--2---Delete-The-Excel-File-&-Bypass-The-Shared-Use-Lock

However, I keep getting a "BadRequest" error with the below message and I am unsure how to fix it. I am attempting to pull in the URI from my create file connector earlier in the flow.
 
"message""Server relative urls must start with SPWeb.ServerRelativeUrl\r\nclientRequestId: fbfd4470-41cb-4734-bad8-a276da50542f\r\nserviceRequestId: 27ceb2a1-3012-9000-71c6-6d18344b3ac4",
 
Any help would be greatly appreciated and any good resources to learn how to make me smarter with these type of connectors would be very helpful. thanks!
 
 
 
  • Ellis Karim Profile Picture
    11,143 Super User 2025 Season 1 on at
    HTTP Request to Sharepoint
    Hi @CU17072334-0
     
    I see that Matthew Devaney's tutorial uses GetByTitle action:
    _api/web/Lists/GetByTitle('File Lock Testing')/GetItemById(1)/recycle
     
    But in your sample screenshot, you have used GetFileByServerRelativeUrl action
    GetFileByServerRelativeUrl()
     
     
    Ellis Karim
    Ellis Karim
    Blog | LinkedIn | Bluesky
    If this solved your issue, please mark it as ✅ Accepted Answer. If it helped, feel free to give it a 🩷 Like!
  • Suggested answer
    Riyaz_riz11 Profile Picture
    3,486 Super User 2025 Season 1 on at
    HTTP Request to Sharepoint
    Hi,
     

    Method 1: Use the file's server-relative URL

    In your HTTP request URL, use:

    _api/web/GetFileByServerRelativeUrl('[SERVER-RELATIVE-PATH]')/recycle()
     

    Where [SERVER-RELATIVE-PATH] should be something like:

    /sites/YourSite/YourLibrary/YourFile.xlsx
     

    Method 2: Extract from Create File output

    If your "Create file" action returns a full SharePoint URL, you need to extract the server-relative portion:


    1. Add a Compose action after your "Create file" action

    2. Use this expression to extract the server-relative URL:

    3.  
    substring(outputs('Create_file')?['body/Path'], indexOf(outputs('Create_file')?['body/Path'], '/sites/'))
    1. Then use this in your HTTP request URL:
    _api/web/GetFileByServerRelativeUrl('@{outputs('Compose')}')/recycle()

    Complete HTTP Request Setup:


    • Method: DELETE

    • URL: https://[yourtenant].sharepoint.com/sites/[yoursite]/_api/web/GetFileByServerRelativeUrl('/sites/[yoursite]/[yourlibrary]/[yourfile]')

    • Headers:

      • Accept: application/json;odata=verbose

      • Content-Type: application/json;odata=verbose

      • X-RequestDigest: Use the form digest value

      • IF-MATCH: *
     
    If I have answered your question, please mark it as the preferred solution ✅ . If you like my response, please give it a Thumbs Up 👍.
    Regards,
    Riyaz
  • WillPage Profile Picture
    2,086 on at
    HTTP Request to Sharepoint
    According to the documentation, deleting a file is done like this:
     
    POST https://{site_url}/_api/web/GetFileByServerRelativeUrl('/Folder Name/{file_name}')
    Authorization: "Bearer " + accessToken
    If-Match: "{etag or *}"
    X-HTTP-Method: "DELETE"
    X-RequestDigest: "{form_digest_value}"
     
     
    Note it's GetFileByServerRelativeUrl
    Also, the dynamic content you want to use within the GetFileByServerRelativeUrl brackets is Full Path as that also contains the file name as well.
     
     

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

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 497 Super User 2025 Season 1

#2
David_MA Profile Picture

David_MA 436 Super User 2025 Season 1

#3
Riyaz_riz11 Profile Picture

Riyaz_riz11 244 Super User 2025 Season 1