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 / HTTP Request to Sharep...
Power Automate
Suggested Answer

HTTP Request to Sharepoint

(0) ShareShare
ReportReport
Posted on by 27
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!
 
 
 
Categories:
I have the same question (0)
  • WillPage Profile Picture
    2,307 Super User 2025 Season 2 on at
    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.
     
     
  • Suggested answer
    Riyaz_riz11 Profile Picture
    3,893 Super User 2025 Season 2 on at
    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
  • Ellis Karim Profile Picture
    11,695 Super User 2025 Season 2 on at
    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!

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 519 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 296 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard