How to create item in a dynamic SharePoint list/site with Power Automate
Posted On March 31, 2021
“Power Automate should determine by itself in which SharePoint list it will create an item, I want to use a dynamic content in the ‘Create item’ action.”
If you ever used the SharePoint ‘Create item’ action, you’ll know that you must select the ‘Site Address’ and ‘List Name’. It makes your work easier as when you select the list it’ll automatically show all available columns to update. But what if you can’t select the list? If you want to use a dynamic content: variable, data from MS Forms, or another item property? In such situations you can’t use ‘Create item’.
If you can’t select a list, the action won’t show you any columns to update, it’ll show only the field ‘Item’.
To create an item with a dynamic list/site, you’ll need an HTTP request.
HTTP request to create SP item
The action you’re looking for is ‘Send an HTTP request to SharePoint’. With ‘Create item’ you’re limited by the developers of the action, but it’s not the case here. Calling the SharePoint REST API through the HTTP request will give you full control over the item creation. You can use dynamic content for the ‘Site Address’ and/or the ‘List name’, and then manually define the column values.
The first part of the request is simple, you just replace the [ListName] with your dynamic content:
The second, more complicated part is the request ‘Body’. It must always start with the “__metadata” object, where the [ListName] dynamic content in the Uri and in the “__metadata” must be the same. That’s what defines the list structure and the available columns.
Once the “__metadata” object is defined, you can add the columns you want to update and their value. You don’t need to add all the columns, you can skip the ones that should stay empty. The example code below will create an item with 3 columns: Column1, Column2 and Column3.
Note: there’re two things to be careful about. Firstly, make sure that all the possible lists for the [ListName] contain all the columns defined in the ‘Body’. Secondly, you must use internal names for all the columns.
If you use Power Automate to create a SharePoint item in a dynamic list/site, you can’t use the default ‘Create item’ action. You must use the HTTP request described above instead.
And it’s not only if you want to split items among multiple lists, I use this solution also in flow ‘templates’. If there’s a flow I’d like to use on multiple SharePoint sites, I don’t want to reconfigure all ‘Create item’ actions for each site. I’ll store the ‘Site Address’ and ‘List Name’ in variables at the beginning, and then use HTTP requests. The one above to create items, and another one to update them.