Create SharePoint Files With REST API in Power Automate

I was recently working on a project where the client wanted to use the REST API to create SharePoint files, get their properties, and delete them using Power Automate.

We need the correct REST API URI to do all these things, starting with GetFolderByServerRelativeUrl.

In this tutorial, I will show you how to use this powerful endpoint to manage files in SharePoint:

  • Create a file in a SharePoint document library
  • Get file details
  • Delete a file from a SharePoint document library, etc.

Create a File in SharePoint Using REST API in Power Automate

I will show you how to create a File in the SharePoint document library using the REST API in Power Automate. Here, I will create a .txt file.

  1. Open Power Automate and create an Instant cloud flow that will trigger the flow manually.
  2. Add a Send an HTTP request to SharePoint action under the trigger and provide the below parameters:
    • Site Address: Select the SharePoint site address from the dynamic content.
    • Method: Select POST as the method.
    • Uri: Provide the below URI:
_api/web/GetFolderByServerRelativeUrl('/sites/YourSiteName/YourLibraryName')/Files/add(url='sample.txt',overwrite=true)

Replace:

  • /sites/YourSiteName/YourLibraryName with the correct path to your library or folder.
  • sample.txt‘ with the name of the file you want to create.
  1. Click the Show All button to display all advanced parameters.
    • Headers: Click on the Switch to text mode button to access the icon and input the JSON. Copy and paste the code below in the Headers section.
{
  "Accept": "application/json;odata=verbose",
  "Content-Type": "text/plain"
}

You can also use “application/json” or “application/octet-stream” depending on your content.

  1. Body:
Hello, this is a file created using REST API in Power Automate!
Create Files in SharePoint Document Library via REST API in Power Automate
  1. Then, save the flow and run it manually.
  2. Once the flow runs, you’ll see the file created in your SharePoint document library with the content you provided.
How to Create a File in SharePoint Using REST API in Power Automate

If you want to create a different type of file, then use the endpoint below:

_api/web/GetFolderByServerRelativeUrl('/sites/YourSiteName/YourLibraryName')/Files/add(url='FileName.extension',overwrite=true)

Now let’s see some of the examples:

Create a Word Document in SharePoint Document Library Using REST API

I am using the same document library to store the Word document file. Let’s see how to create it using Power Automate.

  1. Create an Instant cloud flow with a trigger (Manually trigger a flow).
  2. Add a Send an HTTP request to SharePoint action under the trigger and provide the below parameters:
    • Site Address: Select the SharePoint site address from the dynamic content.
    • Method: Select Post as the method.
    • Uri: Provide the below URI:
_api/web/GetFolderByServerRelativeUrl('/sites/YourSiteName/YourLibraryName')/Files/add(url='report.docx',overwrite=true)
  1. Click on the Show all button to display all the Advanced parameters.
    • Headers: Click on the Switch to text mode button to the icon to input the json. Copy and paste the code below in the Headers section.
{
  "Accept": "application/json;odata=verbose",
  "Content-Type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
}
  1. Body:
Hello, this is a file created using REST API in Power Automate!

Some plain text content will be written, but it won’t be fully formatted like a true Word document.

send http request to sharepoint power automate post create file
  1. Save the flow and run it once it runs successfully. Then, go to the SharePoint document library, and you can see that the Word document was created.
Create Word Document in SharePoint Document Library Using REST API in Power Automate

You can create a Word document file using SharePoint REST API in Power Automate.

Get File Details in SharePoint Library Using REST API in Power Automate

With the Send an HTTP request to SharePoint action and the REST API endpoint, you can get everything from a file’s name and URL to its size, author, and even version info in Power Automate.

To do this, follow the steps below:

  1. Create an Instant cloud flow with a trigger (Manually trigger a flow).
  2. Add a Send an HTTP request to SharePoint action under the trigger and provide the below parameters:
    • Site Address: Select the SharePoint site address from the dynamic content.
    • Method: Select Get as the method.
    • Uri: Provide the below URI:
_api/web/GetFolderByServerRelativeUrl('/sites/YourSiteName/YourLibraryName')/Files('SampleFile.pdf')

Replace:

  • /sites/YourSiteName/YourLibraryName: with the correct path to your library or folder.
  • SampleFile.pdf: with the name of the file you want to get.
  1. Click the Show All button to display all advanced parameters.
    • Headers: Click on the Switch to text mode button to the icon to input the json. Copy and paste the code below in the Headers section.
{
  "Accept": "application/json;odata=verbose"
}
Get File Details in SharePoint Library Using REST API in Power Automate
  1. Now save the flow and run it manually. Once the flow runs successfully, click the Run Flow button. Then, click Send an HTTP request to SharePoint action and check the output section.
Power Automate Get File Details in SharePoint Library Using REST API

Note:

When you use the REST API in Power Automate with the endpoint _api/web/GetFileByServerRelativeUrl(‘/sites/YourSiteName/Shared Documents/YourFile.pdf’), it returns only the file properties and metadata, not the actual file content. This includes details like the file name, server relative URL, unique ID, who created or last modified the file, and values of any custom columns you’ve added in the SharePoint library (like Status, Category, or Project).

Get File From SharePoint Document Library Using REST API in Power Automate

In the above example, we saw how to get the properties and metadata of a file using Rest API in Power Automate. In this example, I will demonstrate how to verify the existence of a file in a SharePoint document library using the SharePoint REST API in Power Automate.

Check the screenshot below, which tells that the sample text file is present in the Report Storage:

Power Automate Get File From SharePoint Document Library Using REST API

Now, I want to check if a file named sample.txt is present in the Report Storage document library. If the file exists, Power Automate will send an email to the specified recipient with the file attached.

Follow the steps below:

  1. Create an instant cloud flow with a trigger: Manually trigger a flow.
  2. Add a Send an HTTP request to SharePoint action:
    • Site Address: Select the SharePoint site address from the dynamic content when the library is present.
    • Method: Select Get as the method.
    • Uri: Provide the below URI:
_api/web/GetFileByServerRelativeUrl('/sites/YourSiteName/YourLibraryName/FileName.extension')/$value

Ensure that you replace the site name, library name, and file name (including the extension) with your specific requirements.

  1. Click on the Show all button to display all the Advanced parameters.
    • Headers: Provide the following headers:
{
  "Accept": "application/octet-stream"
}
Get file in a SharePoint folder using Power Automate
  1. Then, add a Send an email (V2) action to notify the user that the file is present, and provide the required parameters as shown below:
    • To: Provide the user’s email address.
    • Subject: Give a subject to the email.
    • Body: Specify the body using dynamic content.
Hi,

Please find attached the invoice you requested.

File Name: sample.txt  
Date Sent: [utcNow()]


Best regards,  
TSinfo Technologies Pvt. Ltd.
  1. Click on the Show all button to display all the Advanced parameters.
    • Attachments:
      • Name – 1: sample.txt
      • Content – 1: Provide the above HTTP action body using dynamic content:
body('Send_an_HTTP_request_to_SharePoint')
get all files from sharepoint document library using rest api
  1. Now, save the flow and run it manually. Once the flow runs successfully, go to the Outlook account you specified, and you will receive the following email:
Get File From SharePoint Document Library Using REST API in Power Automate

The best part is that you can send any file (PDF, Excel, etc.) using this Power Automate method.

Get All Files From SharePoint Document Library Using REST API in Power Automate

Usually, when we need to get all files from a document library in Power Automate, we use the Get files (properties only) action. However, you can also retrieve files using the SharePoint REST API in Power Automate. Let’s see how to do this.

To verify, I have a SharePoint Document library called Certification Documents, which contains 21 files. Check the screenshot below:

Get all SharePoint Document Library Files in Power Automate

Now, I want to get all the files using the SharePoint Rest Api and count them.

  1. Sign in to Power Automate with valid credentials. Then click on + Create and select Instant cloud flow.
  2. Enter the Flow name and choose the trigger flow (i.e., Manually trigger a flow), then click Create.
  3. Add a Send an HTTP request to SharePoint action, then provide the side address and below required parameters:
    • Method: Select Get as the method.
    • Uri: Provide the below URI:
_api/web/GetFolderByServerRelativeUrl('/sites/PowerAutomateTutorial/CertificationDocuments')/Files
  1. Click on the Show all button to display all the Advanced parameters.
    • Headers: copy and paste the below headers:
{
  "Accept": "application/json;odata=verbose"
}
get all files from sharepoint document library using rest api in Power Automate
  1. Now add the Apply to each control and provide the below expression:
body('Send_an_HTTP_request_to_SharePoint')?['d']?['results']
Power Automate get files from sharepoint document library using rest api
  1. Inside the apply to each control action adds a Compose action and gives the following expression, which returns the file names:
item()?['Name']
Power Automate get all files from sharepoint document library using rest api
  1. Now save the flow and run it manually. After the flow runs successfully, check how many times it applies to each running; in my case, it is 21 because I have 21 files in the SharePoint document library.
Power Automate Get and count All Files From SharePoint Document Library Using REST API

You can get all files from a SharePoint document library using Power Automate with the REST API.

Delete a File in SharePoint Document Library Using REST API

In this example, I will tell you how to delete the file from the SharePoint document library using the REST API in Power Automate.

Here, I will show you two ways to delete the file from the SharePoint Document library in Power Automate with the Rest Api:

  • Delete a file using the Delete method of the REST API
  • Delete a file using the Post method using the REST API

Delete a File using the Delete Method in the REST API

For this example, I am using the SharePoint Library below and want to delete the Jane Doe PDF file. Check the screenshot below:

Power Automate Delete File using Delete Method in REST API

Follow the below steps to delete the file using the REST API DELETE method:

  1. Go to Power Automate and click Create -> Instant Cloud Flow. Select Manually trigger a flow as the trigger.
  2. Add a Send an HTTP request to SharePoint action to delete files and provide the following parameters:
    • Site Address: Select the SharePoint site address from the dynamic content.
    • Method: Select DELETE as the method.
    • Uri: Provide the below URI:
_api/web/getFileByServerRelativeUrl('/sites/PowerAutomateTutorial/PDFDocument/Jane Doe.pdf')

Here:

  • PowerAutomateTutorial: Site Internal Name
  • PDFDocument: SharePoint Library Internal Name
  • Jane Doe.pdf: File Name with extension
delete file from sharepoint document library using rest api in Power Automate
  1. Now save the flow and run it manually. After the flow successfully runs, go to the SharePoint library. You can see the file has been deleted.
Power Automate Delete File in SharePoint using REST API

Delete File Using Post Method in REST API

In this example, I use the same document library, but I will delete the Project Deadlines Excel file here. Let’s check out:

  1. Create an Instant cloud flow with a trigger (Manually trigger a flow).
  2. Add a Send an HTTP request to SharePoint action, then provide the side address and below required parameters:
    • Method: Select Post as the method.
    • Uri: Provide the below URI:
_api/contextinfo
  1. Click on the Show all button to display all the Advanced parameters.
    • Headers: copy and paste the below headers:
{
  "Accept": "application/json;odata=verbose"
}
Power Automate Deleting a file from a Document Library with REST API
  1. Add a Send an HTTP request to SharePoint action, then provide the side address and below required parameters:
    • Method: Select Post as the method.
    • Uri: Provide the below URI:
_api/web/getfilebyserverrelativeurl('/sites/PowerAutomateTutorial/ReportStorage/Project Deadlines.xlsx')
  1. Click on the Show all button to display all the Advanced parameters.
    • Headers: copy and paste the below headers:
{
  "Accept": "application/json;odata=verbose",
  "X-RequestDigest": "body('Send_an_HTTP_request_to_SharePoint')?['d']['GetContextWebInformation']['FormDigestValue']
",
  "IF-MATCH": "*",
  "X-HTTP-Method": "DELETE"
}
Power Automate Delete File Using Post Method in REST API
  1. Save the flow and run it manually. Once the flow runs successfully.
  2. Go to the SharePoint library. You can see the file has been deleted.
Power Automate Deleting Files with REST API

I hope you found this tutorial helpful.

You may also like:

Power Apps functions free pdf

30 Power Apps Functions

This free guide walks you through the 30 most-used Power Apps functions with real business examples, exact syntax, and results you can see.

Download User registration canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App