Flow: Get SharePoint List Item Through Rest API
In this article
Introduction
In this article, we will explore how to get a SharePoint list item through REST API in Microsoft Flow.
I have created a “City” list and added an item in the Title column. Now, we will get the data of list items through REST API in Microsoft Flow.
https://csharpcorner-mindcrackerinc.netdna-ssl.com/article/microsoft-flow-how-to-get-sharepoint-list-item-through-rest-api-in-microsoft-f/Images/How%20To%20Get%20SharePoint%20List%20Item%20Through%20Rest%20API%20In%20Microsoft%20Flow.png
Scenario
In SharePoint Online custom list, when an item is created, a mail needs to be sent using the Title column in the mail. This needs to be achieved through Microsoft Flow.
Process
Let’s move to Microsoft Flow.
Step 1
Click the URL here to go to Microsoft Flow. The following screen appears. In the left navigation, select Templates. From the main window, now, select the *"Send an email when a new item is created in SharePoint" *template.
https://csharpcorner-mindcrackerinc.netdna-ssl.com/article/microsoft-flow-how-to-get-sharepoint-list-item-through-rest-api-in-microsoft-f/Images/How%20To%20Get%20SharePoint%20List%20Item%20Through%20Rest%20API%20In%20Microsoft%20Flow02.png
Step 2
After selecting the template, the following screen appears. Click the "Continue" button.
https://csharpcorner-mindcrackerinc.netdna-ssl.com/article/microsoft-flow-how-to-get-sharepoint-list-item-through-rest-api-in-microsoft-f/Images/How%20To%20Get%20SharePoint%20List%20Item%20Through%20Rest%20API%20In%20Microsoft%20Flow03.png
Step 3
On the next screen, add a new action by clicking the https://csharpcorner-mindcrackerinc.netdna-ssl.com/article/microsoft-flow-how-to-get-sharepoint-list-item-through-rest-api-in-microsoft-f/Images/How%20To%20Get%20SharePoint%20List%20Item%20Through%20Rest%20API%20In%20Microsoft%20Flow04.png sign and expand.
https://csharpcorner-mindcrackerinc.netdna-ssl.com/article/microsoft-flow-how-to-get-sharepoint-list-item-through-rest-api-in-microsoft-f/Images/How%20To%20Get%20SharePoint%20List%20Item%20Through%20Rest%20API%20In%20Microsoft%20Flow05.jpg
Start Microsoft Flow implementation step by step
In the Flow first block, the following section appears. Add the site address of your relative site collection URL and select the List name in which you implemented the operation.
https://csharpcorner-mindcrackerinc.netdna-ssl.com/article/microsoft-flow-how-to-get-sharepoint-list-item-through-rest-api-in-microsoft-f/Images/How%20To%20Get%20SharePoint%20List%20Item%20Through%20Rest%20API%20In%20Microsoft%20Flow06.jpg
In the second block, the following section appears In this section, declare the variable name and set the created itemId.
https://csharpcorner-mindcrackerinc.netdna-ssl.com/article/microsoft-flow-how-to-get-sharepoint-list-item-through-rest-api-in-microsoft-f/Images/How%20To%20Get%20SharePoint%20List%20Item%20Through%20Rest%20API%20In%20Microsoft%20Flow07.jpg
The third block asks us to add the ‘Send an HTTP request to SharePoint’ action to execute REST API on current created ItemId.
https://csharpcorner-mindcrackerinc.netdna-ssl.com/article/microsoft-flow-how-to-get-sharepoint-list-item-through-rest-api-in-microsoft-f/Images/How%20To%20Get%20SharePoint%20List%20Item%20Through%20Rest%20API%20In%20Microsoft%20Flow08.jpg
Lots of people are confused about how to parse the JSON Schema data. Let us see the steps on how to get the Parse JSON Schema data.
Open the site in a browser and press F12 to open the browser console prompt. Add the following JavaScript code. This code will add a jQuery CDN in the head section of your page which will help us to call the REST API.
var element = document.createElement("script");
element.type = "text/javascript";
element.src = "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js";
document.head.append(element);
https://csharpcorner-mindcrackerinc.netdna-ssl.com/article/microsoft-flow-how-to-get-sharepoint-list-item-through-rest-api-in-microsoft-f/Images/How%20To%20Get%20SharePoint%20List%20Item%20Through%20Rest%20API%20In%20Microsoft%20Flow09.jpg
Call the REST API and in debugger mode, assign JSON.stringify(data) to the variable. Don’t stop debugger before assigning the JSON data to declare variable (jsonvar ). Copy the variable value.
$.ajax({
url: "https://pointerone.sharepoint.com/sites/SPFXDemo/_api/web/lists/GetByTitle('City')/items(1)",
method: 'GET',
headers: {
"Accept": "application/json; odata=verbose",
"content-type": "application/json; odata=verbose",
}, success: function (data){
debugger;
}});
https://csharpcorner-mindcrackerinc.netdna-ssl.com/article/microsoft-flow-how-to-get-sharepoint-list-item-through-rest-api-in-microsoft-f/Images/How%20To%20Get%20SharePoint%20List%20Item%20Through%20Rest%20API%20In%20Microsoft%20Flow10.jpg
In the fourth block, we need to add the ‘Parse JSON’ action to execute the REST body Schema.
https://csharpcorner-mindcrackerinc.netdna-ssl.com/article/microsoft-flow-how-to-get-sharepoint-list-item-through-rest-api-in-microsoft-f/Images/How%20To%20Get%20SharePoint%20List%20Item%20Through%20Rest%20API%20In%20Microsoft%20Flow11.jpg
Click the above screen pop up. Use sample payload to generate schema link. Then, the following screen pops up. Here, paste the JSON.stringify(data) in the below block. Click the "Done" button.
https://csharpcorner-mindcrackerinc.netdna-ssl.com/article/microsoft-flow-how-to-get-sharepoint-list-item-through-rest-api-in-microsoft-f/Images/How%20To%20Get%20SharePoint%20List%20Item%20Through%20Rest%20API%20In%20Microsoft%20Flow12.jpg
In the last section, we add the ‘send mail’ action. Here, let us set the To, Subject, and Body fields and save the flow.
https://csharpcorner-mindcrackerinc.netdna-ssl.com/article/microsoft-flow-how-to-get-sharepoint-list-item-through-rest-api-in-microsoft-f/Images/How%20To%20Get%20SharePoint%20List%20Item%20Through%20Rest%20API%20In%20Microsoft%20Flow13.png
Output
Add an item in the City List.
https://csharpcorner-mindcrackerinc.netdna-ssl.com/article/microsoft-flow-how-to-get-sharepoint-list-item-through-rest-api-in-microsoft-f/Images/How%20To%20Get%20SharePoint%20List%20Item%20Through%20Rest%20API%20In%20Microsoft%20Flow14.jpg
See the Microsoft Flow status.
https://csharpcorner-mindcrackerinc.netdna-ssl.com/article/microsoft-flow-how-to-get-sharepoint-list-item-through-rest-api-in-microsoft-f/Images/How%20To%20Get%20SharePoint%20List%20Item%20Through%20Rest%20API%20In%20Microsoft%20Flow15.jpg
In Outlook mail, the screen appears with the currently added city name.
https://csharpcorner-mindcrackerinc.netdna-ssl.com/article/microsoft-flow-how-to-get-sharepoint-list-item-through-rest-api-in-microsoft-f/Images/How%20To%20Get%20SharePoint%20List%20Item%20Through%20Rest%20API%20In%20Microsoft%20Flow16.jpg
Note