Hello Friends,
Welcome back with another post on Power Automate. Have you ever thought to use REST API in Power Automate. You can get data in Power Automate using "Get Items" action. But if someone asks you to use REST API in Power Automate to Insert/Update/Delete/Read. Is it possible?
Yes, you can use REST API in Power Automate to get the data as well as for Insert / Update / Delete. Today, we will talk about "Send an HTTP request to SharePoint" action in Power Automate. This action is specific to apply all REST API actions in SharePoint and it's a free action unlike other HTTP action which are PREMIUM.
So, here, we will learn about CRUD operations using REST API, Power Automate and PowerApps. It will be a series of posts. Let's start with Create operation.
- Let's create a simple list "ListForRESTAPI" in SharePoint Online with only 2 columns-
- Title (Single line of text)
- PinCode (Number) (Decimal Places 0)
- Now click on Integrate >> Power Apps >> Create an app. It will ask you to provide a name for App. Let's give the name as "RESTAPICRUPApp". Click on "Create" button.
- The App will be created with Browse Screen, Detail Screen and Edit Screen (For New & Edit).
- In this post, we will work on "Add New Item". Therefore, we will choose EditScreen1 to perform our activities. But before that, we need a Power Automate that will be used to save the data in SharePoint list. This Power Automate will use REST API to perform the activity.
- So, open Power Automate portal, click on "+ Create", then choose "Instant cloud flow".
- It will open a popup to choose the type of flow you want to create and also to provide a name to it. Choose "PowerApps" and give flow name as "HTTPCRUD-Create" and click on Create button.
- With this, we will get the Power Automate created as below-
- Now we will add steps and actions.
- First of all, we need the input values for "Title" and "PinCode" from PowerApps that will be saved into SharePoint List. For this, we will create 2 input parameters using Compose action.
- For this, click on "+ New step", a popup will open, type Compose in the input box provided to filter the Compose step. Click on the Compose step displaying in the filtered content. It will add Compose step in our Power Automate. Rename it to "ComposeTitle".
- Now we have to set it as a parameter that will take value from PowerApps. For this click on the Inputs text box of this Compose step and choose "Ask in PowerApps" from the Dynamic content list.
- It will create a input parameter named "ComposeTitle_Inputs" that will be reflected in PowerApps while using this Power Automate.
- Similar way, we will create another input parameter "ComposePinCode_Inputs"
- Now the major part arrives. We will now apply REST API step to insert the data in SharePoint list. For this, click on "+ New step" and type HTTP in search box. The search result will show the first option as "Send an HTTP request to SharePoint".
- Select this option. We will below screen-
- Choose the address of SharePoint site in "Site Address",
- Choose "POST" as the "Method".
- Fill in the "Uri" as "_api/web/lists/getbytitle('ListForRESTAPI')/items". Change the list name if you have chosen something else. 😉
- In Headers-
- Enter key as "content-type"
- Enter value as "application/json;odata=nometadata"
- Now comes to "Body" section. Provide a json format of input values with column names.
- For Title, select the Outputs of ComposeTitle
- For PinCode, select the Outputs of ComposePinCode
- Click on Save to save the Power Automate. This way Power Automate has been created. Now get back to PowerApps. So, go back to step no 7.
- Click on EditScreen1 and add a button named "btnAdd" and write its Text as "Add".
- Now update the formula for "OnSelect" action of this button. For this click on the formula box of OnSelect of btnAdd. Now click on "Action" >> "Power Automate". It will open a popup where all the PowerApps flows will appear. You will find the recently created Power Automate "HTTPCRUD-Create" here. Click on this flow. Once clicked, it will show a yellow bar with text as "Adding".
- Once added, the message will change and the Power Automate will be added in formula bar.
- As you see, the tooltip of the formula bar is showing the complete Power Automate (with it's input parameters). Now you need to just provide the value to it as per the sequence.
- It's done. Now you can add navigation back to list screen after this formula. With this the complete formula will be-
'HTTPCRUD-Create'.Run( DataCardValue3.Text, DataCardValue4.Text ); Navigate( BrowseScreen1, None );
- Save the PowerApps and Let's try now to insert a data.
- When you execute the PowerApps, by default the BrowseScreen (list of records) will appear. As there is no record in list as of know, it will show blank screen.
- Click on + icon at top right corner. It will open the EditScreen in New Form mode.
- Input the Title and PinCode and click on Add button placed at bottom.
- PowerApps will call the Power Automate by passing the data we have input. Power Automate will save the data in SharePoint list. Once the process will complete, the Navigate action will executed and the app will redirect us back to Browse Screen.
- Here it may be possible that you still get the blank screen because the list collection is not refreshed. Therefore, click on Refresh icon placed at top. You will find that the screen is now showing the record, we had inserted just now.
- The record inserted is also reflecting in SharePoint list.
- With this, Part 1 of the series is over. We have learned the insertion of record using PowerApps, Power Automate and REST API.
- If you want to check the status of HTTP request in Power Automate and then also want to return the ID of record created along with Response message, please visit my Add-Ons Post-
- In next Part, we will learn the Update feature.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.