Send An HTTP Request To SharePoint In Power Automate (MS FLOW)

Introduction

 
Power Automate, previously known as MS Flow, is a cloud-based service that allows users to create automated workflows across multiple applications and services. It is one of the important pillars of the Microsoft Power Platform. It has n-number of third parties connector (in the form of APIs) available which can be leveraged to perform various actions that require lots of coding and cumbersome effort to implement. Being a low code platform, it doesn’t require any software to start development, all that's required to start development is proper O365 license.
 
Power Automate comes with a very intuitive UI, where users can see the various available actions under a different sets. Once they choose any of the actions, it gets added to the flow with insightful UI, where the user can directly feed the input to get the required output.
 
In this article I am going to cover the most useful action “Send an HTTP request to SharePoint”. As a SharePoint developer, most of us regularly use the HTTP call in our code, as it makes code development easy. In this article, we will see the most used methods, such as GET, POST, PATCH, and DELETE with examples.
 
Prerequisites
  1. Log in to the flow portal with your Office 365 credentials.
  2. For this article, I have created a SharePoint List. Please find its schema below.

    SharePoint Rest API In Power Automate (MS FLOW)

  3. For my flow, the trigger is manual, you can choose as per your business requirements.

    SharePoint Rest API In Power Automate (MS FLOW)

  4. Our focus will be on template Send an HTTP request to SharePoint and its Methods.
  • GET
  • POST
  • PATCH
  • DELETE
SharePoint Rest API In Power Automate (MS FLOW)
 
Let’s get started.
 
Click on New Step and search for the Action “Send an HTTP request to SharePoint”. Once you get the option, click on it. It will add the action to your flow.
SharePoint Rest API In Power Automate (MS FLOW)
  • Site Address: Choose your SharePoint Site from the dropdown.
  • Method: You can choose the method as per your requirement.
  • Uri: _api/web/lists/getbytitle(“List Name”), other attributes like top, filter, etc can be added here.
  • Headers: As per business requirements.
  • Body: JSON body as per business requirements.
Method Name: GET
 
It is one of the most common and widely used methods. If we have sufficient permission to access the data, then we can simply use GET to retrieve all the results from the endpoint.
 
Our GET method call is as shown below:
 
SharePoint Rest API In Power Automate (MS FLOW)
  • Site Address: Choose your SharePoint Site from the dropdown.
  • Method: POST
  • Uri: _api/web/lists/getbytitle(“List Name”), other attributes like top, filter, etc., can be added here.
  • Headers: We have provided No Header for the GET request.
Now, manually trigger the flow to see the response. Grant asked permission by the flow.

SharePoint Rest API In Power Automate (MS FLOW)
 
With Success code: 200, it shows we have successfully executed the GET Method. Our focus area will be the response body which is in json format, so we need to use apply to each action get a result from the previous step, and then we use Compose Action to get a specific result.
 
Next, we will “Apply to each” to get all the required fields.
 
SharePoint Rest API In Power Automate (MS FLOW)
 
Now, when we trigger the flow and see the result. Flow will get each item and display the User Name, User Department, and Profile Link as shown below.
  • User Name for the first Item
SharePoint Rest API In Power Automate (MS FLOW)
  • User Department for the First User
SharePoint Rest API In Power Automate (MS FLOW)
  • Profile link for the first user
SharePoint Rest API In Power Automate (MS FLOW)
 
Furthermore, we can process to get the profile link description and URL as per our business needs.
 
Method Name: POST
 
POST is another important and frequently used method of REST API which is used to create a new item and even it can be used to create a new list/library. To see the POST method, we will add new Action “Send an HTTP request to SharePoint” in our existing flow. This time, we are going to select POST in our method dropdown.
 
SharePoint Rest API In Power Automate (MS FLOW)
  • Site Address: Choose your SharePoint Site from the dropdown.
  • Method: POST
  • Uri: _api/web/lists/getbytitle(“List Name”)
  • Headers: In case of post we need to add a header. In the Headers section there is a key-value pair combination.
    1. content-type :application/json;odata=verbose  
  • Body: JSON body as per business requirements.
    1. {    
    2. "__metadata": { "type""SP.Data.ListForMSFlowDemoListItem" },    
    3. "UserName""Demo User Post",    
    4. "UserDepartment""Finance",    
    5. "UserProfileLink":    
    6. {    
    7.  "__metadata": {    
    8.     "type""SP.FieldUrlValue"    
    9.   },    
    10.   "Description""Oracle",    
    11.   "Url""https://www.Oracle.com"    
    12. }    
    13. }   
The important point to note here is,
  1. "__metadata": { "type""SP.Data.ListForMSFlowDemoListItem" }   
You need to be specific while adding type. In my case, the list name is ListForMSFlowDemo so type is SP.Data.ListForMSFlowDemoListItem. This will change according to list name, so you should always provide correct value. If you have used space in list name replace it with _x0020_ i.e.
  1. List Name : List For MSFlow Demo    
  2. Type : List_x0020_For_x0020_MSFlow_x0020_DemoListItem    
The body part will have a schema of the list item you want to create. Make sure you are including all mandatory columns in the schema. Now run the flow to check the result.
 
Success code: 201 means our post method completed successfully. Now we will verify the SharePoint list to check
 
SharePoint Rest API In Power Automate (MS FLOW)
We can see the new item has been created using the POST method.
 
Method Name: PATCH
 
PATCH comes into the scene when we want to update the list Item. In this method we can send the item id of the element and update its field values. To do so, we will again add the Action “Send an HTTP request to SharePoint” in our flow and this time selected method will be PATCH. It will look like the following:
 
SharePoint Rest API In Power Automate (MS FLOW)
  • Site Address: Choose your SharePoint Site from the dropdown.
  • Method: PATCH
  • Uri: _api/web/lists/getbytitle(“List Name”)(ItemID) , id of item which will be updated
  • Headers: In case of post we need to add a header. In the Headers section there is a key-value pair combination. 
    1. KEY : content-type Value : application/json;odata=verbose    
    2. KEY :  IF-MATCH  Value : *    
    3. Note : Instead of * we can also pass eTag of item to control concurrency.   
  • Body: JSON body as per the business requirements.
    1. {    
    2.    "__metadata": { "type""SP.Data.ListForMSFlowDemoListItem" },    
    3.    "UserDepartment""HR"    
    4. }  
The key point to note here is that we are updating department of Demo User 1 from IT to HR. We have passed the item ID of Demo user 1 in Uri text field. In our case item ID is 1. Now let’s run the flow and see the result.
 
SharePoint Rest API In Power Automate (MS FLOW)
 
Success code: 204 means we have successfully updated the specific list item. Now let’s verify the list item.
 
SharePoint Rest API In Power Automate (MS FLOW)
 
We can see that the User Department is updated to HR from IT for Demo User 1.
 
Method Name: Delete
 
This method is used to delete the item. To delete all we need to do is to pass the item we want to delete. To see the DELETE method, we will add new Action “Send an HTTP request to SharePoint” in our existing flow. This time we are going to select DELETE in our method dropdown.
 
SharePoint Rest API In Power Automate (MS FLOW)
 
We are going to target the Item id 5 to delete using the action “Send an HTTP to SharePoint”.
 
SharePoint Rest API In Power Automate (MS FLOW)
  • Site Address: Choose your SharePoint Site from the dropdown.
  • Method: PATCH
  • Uri: _api/web/lists/getbytitle(“List Name”)(ItemID) , id of item which will be updated
  • Headers: In case of post we need to add the header. In the Headers section, there is a key-value pair combination.
    1. content-type : application/json;odata=verbose    
    2. IF-MATCH : *    
    3.  X-HTTP-Method : DELETE   
Now run the flow to check the result.
 
SharePoint Rest API In Power Automate (MS FLOW)
 
Success code: 200 means we have successfully deleted the item with item ID: 5. Now let’s verify our list.
 
SharePoint Rest API In Power Automate (MS FLOW)
 
There is no item with Item ID 5.
 
With this, I have covered the frequently used REST API method in action “Send an HTTP request to SharePoint”.
 

Conclusion

 
We can effectively use this action to perform various CRUD operations which at times become challenging to achieve using the OOB method provided in Power Automate.


Similar Articles