CRUD operation using Send request to SharePoint Action in Power Automate.

 CRUD operation using Send request to SharePoint Action

Send request to SharePoint Action is an important Action in Power Automate.

Perfect use case for this Action will be when Out of Box actions are failing to do the job, like when your flow is failing to read the JSON that you have passed to it. This action can be used to do all the CRUD operations on SharePoint lists using the below methods.

  • GET
  • POST
  • PATCH
  • DELETE
However, the best part I like about it is that you don't even need to refresh the SharePoint Pages to see the end result.

Lets dig into this.

We have a simple Flow testing list created in SharePoint.

It has a Title column, a choice column and a People picker with single values column.

GET Method.

For all the flows that I showcase here I will only trigger them using Manual trigger. But that is no way a dependency and in actual practice you can trigger your flows based on any conditions and even from Power Apps and they will work like a charm.



Site Address : Select your site from the dropdown, if your site doesn't show up in the dropdown and Power Automate is acting grumpy just select custom and type in your site address.

Method: Select GET from the dropdown as we just want to read the items form the SharePoint list.

Uri: Here is where the magic happens type in the below statement.
_api/web/lists/getbytitle('yourlistName')/items?

Headers: accept as key and application/json; odata = verbose.

we can odata = verbose in dev environment.


POST Method

In the next method, there are two couple of changes.

Site Address : Select your site from the dropdown, if your site doesn't show up in the dropdown and Power Automate is acting grumpy just select custom and type in your site address.

Method: Select POST from the dropdown as we want to add an item to the SharePoint list.

Uri: Here is where the magic happens type in the below statement.
_api/web/lists/getbytitle('yourlistName')/items

Headers: accept as key and application/json; odata = verbose.

The body looks like 
{
'__metadata':{ 'type':'SP.Data.FlowTestingListItem'}, 'Color':'Yellow'
}

PATCH Method

Patch method is nothing but what we call Update method. Its used to update existing SharePoint list item values.

So we will select the same site address and then the below fields will be updated as below

Site Address : Select your site from the dropdown, if your site doesn't show up in the dropdown and Power Automate is acting grumpy just select custom and type in your site address.

Method: Select PATCH from the dropdown as we want to update an item to the SharePoint list.

Uri: Here is where the magic happens type in the below statement.
_api/web/lists/getbytitle('yourlistName')/items(ID)
we can get ID, via the SharePoint ID column.

Headers: accept as key and application/json; odata = verbose.

Also, here i wish to tell you guys you can also pass this ID to the flow, or set it when calling the Flow via PowerApps. So this makes it very dynamic.

wait but we do have a change in Body

The body looks like 
{
'__metadata':{ 'type':'SP.Data.FlowTestingListItem'}, 'Color':'Yellow','PeoplePickerSingleId':7
}

yes __metadata is nothing but two successive underscore before metadata.
SP.Data.YourlistNameItem. Following this i am setting values to SharePoint columns.
Color as Yellow and PeoplePickerSingle as 7 as that is what my JSON retrieves when i do a GET item on the SharePoint list. So if you wish to know your ID go back to the flow and test it.


DELETE Method



In this method what we are doing is making changes to the below 

Site Address : Select your site from the dropdown, if your site doesn't show up in the dropdown and Power Automate is acting grumpy just select custom and type in your site address.

Method: Select DELETE from the dropdown as we want to update an item to the SharePoint list.

Uri: Here is where the magic happens type in the below statement.
_api/web/lists/getbytitle('yourlistName')/items(ID)
we can get ID, via the SharePoint ID column.

Headers: IF-MATCH as key and  value as * and you can also add 
X-HTTP-Method : DELETE.

Run the flow if you get Success Code: 200  the item will be successfully deleted.


Conjecture:  I believe all these methods and Send request to SharePoint as an Action is super useful when Out of box Actions in Power Automate fail.

Comments

Popular posts from this blog

Creating Nested Galleries in Power Apps. (Parent-Child Relationship)

How to reset a datepicker control in PowerApps?

Reset () function failing to work on Edit form for Combo boxes in Power App.