Share via


Flow: Get SharePoint List Item Through Rest API

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

  1. 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

  2. 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

  3. 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

  4. 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.

    1. 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. 

      1. var element = document.createElement("script");  
      2.     element.type = "text/javascript";  
      3.     element.src  = "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js";  
      4.     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.

 

  1. $.ajax({    
  2.             url: "https://pointerone.sharepoint.com/sites/SPFXDemo/_api/web/lists/GetByTitle('City')/items(1)",    
  3.                   method: 'GET',    
  4.              headers: {    
  5.                 "Accept": "application/json; odata=verbose",    
  6.                 "content-type": "application/json; odata=verbose",                       
  7.     
  8.             }, success: function (data){   
  9.                 debugger;  
  10.             }});  

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

  1. 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

  2. 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

  3. 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