Dynamically adding a new item to a list using SharePoint REST API and Power Automate

Share the love

As you may or may not know, right now you cannot choose a list dynamically in some of the SharePoint actions in Power Automate. Anything that involves Power Automate loading the list item or file properties into the UI cannot be done. Some of these actions include creating and updating list or file items.

However, we can dynamically set a site, list or library, and use REST API to make changes.

In this blog post, we’ll concentrate on how to add an item to a list. Perhaps you have multiple lists with the same content type, or have a similar structure, but you want to create an item in a list when your flow criteria is met.

In my case, I have two lists. However, depending on the list name that gets passed in through the parent flow, I want to create an item in that particular list. Instead of creating two Create item actions, I added a Send an HTTP request to SharePoint action and use my dynamic list name in the URI.

We can add an item to a list by calling the following REST API using the POST method.

_api/web/lists/GetByTitle('List Name')/items

In the body section, we add the values of the columns. The column names are the internal names (not the display names) of the columns.

To find the code that is used in the last line of the body section:

"__metadata": { "type": "SP.Data.ListNameListItem" }

Type the following URI into your browser and then search for <d:ListItemEntityTypeFullName>. After the start of this node, you should see text that begins with SP.Data.

https://<tenant>/sites/<site>/_api/web/lists/getbytitle('List Name')

Copy this text into the last line of the Body, pasting over where I have SP.Data.ListNameListItem.

_api/web/lists/GetByTitle('variables('ListName')')/items
{
  "Accept": "application/json;odata=verbose",
  "Content-Type": "application/json;odata=verbose"
}
{
   "Title":"triggerBody()?['text_3']",
   "WorkflowID":"triggerBody()['text']",
   "ResponseStatus":"Pending",
   "WorkflowStatus":"In Progress",
   "__metadata": { "type": "SP.Data.ListNameListItem" }
}

Once this code runs, a new item will be added to your list.


Share the love

Leave a Reply

Your email address will not be published. Required fields are marked *