Introduction
Managing large datasets in SharePoint can be a challenge, especially when you need to populate a list with hundreds or thousands of items. Manually creating items or using individual API calls is slow and inefficient. Fortunately, Power Automate, combined with SharePoint’s $batch REST API endpoint, allows you to batch create items efficiently. In this blog, I’ll Walk you through building a Power Automate Flow to populate a SharePoint list with new items in batches - perfect for data imports or refreshes.
Why Use Batch Creation?
Scalability: Easily handle thousands of items.
Automation: Eliminate manual entry.
Use Case
Step 1: Setting Up the Batch Create Flow
Initialize Loop Control
Add a Set Variable action:
Name: LoopControl
Type: Integer
Value: -1
Add a Scope
Use a Scope action to organize the logic. Inside it:
Define SharePoint List Details
Add a Compose action (named "settings"):
{
"siteAddress": "https://tenant-name.sharepoint.com/sites/site-name/",
"listName": "List Name",
"batchSize": 1000
}
Add a Select action (named GenerateSPData) to prepare data from source of data (you will need to fetch data from actual source of data - e.g. Excel File with relevant action, and get it into this select action):
From: Your dataset array.
Map: Format fields (e.g., {"Title": item()['Title']}).
Create a Batch Template
Add a Compose action (named batchTemplate):
--changeset_@{actions('settings')?['trackedProperties']['changeSetGUID']}
Content-Type: application/http
Content-Transfer-Encoding: binary
POST @{outputs('settings')['siteAddress']}_api/web/lists/getByTitle('@{outputs('settings')['listName']}')/items HTTP/1.1
Content-Type: application/json;odata=verbose
|RowData|
Step 2: Looping Through the Creation Process
Add a Do Until loop (until LoopControl equals 0). Inside:
Add a Select action:
From: @{take(skip(body('GenerateSPData'), mul(outputs('settings')['batchSize'], iterationIndexes('Do_until'))), outputs('settings')['batchSize'])} Map: @replace(outputs('batchTemplate'), '|RowData|', string(item()))
2. Update LoopControl
Add a Set Variable action:
@{length(body('Select'))}
3. Prepare Batch Data
Add a Compose action (named batchData):
@{join(body('Select'), decodeUriComponent('%0A'))}
Add a Send an HTTP Request to SharePoint action:
Method: POST
URI: /_api/$batch
Headers:
X-RequestDigest: digest Content-Type: multipart/mixed; boundary=batch_@{actions('settings')?['trackedProperties']['batchGUID']}
Body:
--batch_@{actions('settings')?['trackedProperties']['batchGUID']} Content-Type: multipart/mixed; boundary="changeset_@{actions('settings')?['trackedProperties']['changeSetGUID']}" Content-Length: @{length(outputs('batchData'))} Content-Transfer-Encoding: binary @{outputs('batchData')} --changeset_@{actions('settings')?['trackedProperties']['changeSetGUID']}-- --batch_@{actions('settings')?['trackedProperties']['batchGUID']}--
5. Check Results
Add a Compose action:
@{base64ToString(body('sendBatch')['$content'])}
![]() |
Do until Action |
How It Works?
Why Go with Batch Creation?
-
- Quick Wins: Fewer API hits mean rapid results.
- Grows with You: Handles thousands of items like a champ.
- No More Manual Mess: Frees you from tedious data entry.
Conclusion
This Power Automate solution simplifies the process of populating SharePoint lists, making it faster and more scalable with the GenerateSPData action. Whether you're adapting it to fit your own data or troubleshooting a specific use case!
No comments:
Post a Comment