Hello,
Is it possible to import a spreadsheet via flow? I don't want to use the loop over all items in the spreadsheet and create a list item in the SharePoint list for each.
I was thinking more of a "Send an HTTP request to SharePoint" to import a spreadsheet.
Thank you!
regards,
It is possible to create files in SharePoint using flow. I have done it with text files and I have done it with Excel files as well, but I am getting an error decoding the Excel content. I am pretty sure the error I'm getting it is just a problem of getting the right encoding/decoding function (that I have not found yet). What you have to do is send an HTTP post request that contains the Excel file content in the body of the request. You need to have an HTTP flow request that reads that body of the request and uses it with a SharePoint Create File action. In my particular examples, I have used Python to send the file via an HTTP request.
FLOW COMPONENTS
1. HTTP POST will give you the URL that you should call to send the file content.
Copy the URL that you will get from this component, as soon as you save your flow. This is the URL that you will have to call to send the file to.
2. Parse JSON with a schema that reads the site_address, application_name, and target_path and file content (see it below)
{
"type": "object",
"properties": {
"site_address": {
"type": "string"
},
"target_path": {
"type": "string"
},
"file_name": {
"type": "string"
},
"file_content": {
"type": "string"
}
}
}
3. SharePoint Create File
You will use the Json variables read in the step below to feed site_address (the URL of the target SharePoint site), folder_path (The path to the library/folder in SharePoint where you will save your file), file_name (the name of the file you will upload) and file_content (the content of your file).
And that's it, you will be able to upload files to SharePoint, just be careful because there is no security to scan what is uploaded and whoever has the HTTP URL can upload files to your SharePoint site.
The Python code to upload the file is below:
import requests
import json
def upload_text_file_to_powerautomate(site_address, file_location, file_name, target_path):
"""
Description: uploads a text file to a SharePoint folder, whose path is specified using a PowerAutomate flow.
Make sure the flow is turned on
:site_address: SharePoint site address
:target_path: Path to the folder in the SharePoint site where the file will be uploaded to
:file_location: Local folder in the sending computer that is sending the file
:file_name: Name of the file that will be uploaded
"""
power_automate_url = "<the_url_from_your_power_automate_https_component" # copy / paste this URL from PowerAutomate HTTPS component
full_file_location = os.path.join(file_location, file_name) # puts together the file location and file name
with open(full_file_location, 'rb') as f:
file_content = f.read() # read the content of the file
data = {
'site_address': site_address,
'target_path': target_path,
'file_name': file_name,
'file_content': file_content
}
data_json = json.dumps(data) # converts the dictionary to a json format
r = requests.post(power_automate_url, json= data_json) # uploads the json data to the PowerAutomate HTTP web service
# calling the function to upload the file to SharePoint
upload_text_file_to_powerautomate(
site_address= "https://<your_target_sharepoit_site>"
file_location= "<where_you_have_the_file_to_upload>, e.g.c:\my_folder_location"
target_path= "your_target_path, e.g. /Shared Documents/test"
file_name= "my_text_file.txt"
)
the code above uploads text files and also can upload Excel file, but the problem I get is when I upload an excel file to SharePoint and I try to open the Excel file, I get an error saying that the file is corrupt 😞 I am pretty sure is because somehow I have to decode the binary content in a way that Excel is able to understand it. If someone knows how to convert this content, we have the full solution to upload Excel files to SharePoint using HTTP.
I hope this helps,
Noah
Hi @Flowbginner,
I am afraid it is impossible to do it. Here is the request API of Working with the SharePoint list and items.
Read it and you couldn't find any API could create a bunch of items in one HTTP request.
If you want to import the Excel table into SharePoint, the method you couldn't avoid is using the Apply to each action.
Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.