Fetching SharePoint List Items Using A Simple HTTP REST Command

In this article, I will introduce you to an online service I created that allows you to code against certain services without using an SDK, simply by sending HTTPS REST commands. In this article, I will demonstrate how this works against SharePoint Online; however other services are also available.

Please note that I built this service with the community in mind, and as a result, it is free for simple use. The service stores your configuration settings securely so that the actual service secrets (such as your SharePoint password) are not stored on the client code.

Developing without an SDK makes it much easier to code IoT, web and Mobile projects, and works regardless of the operating system or programming language. That's because you can make simple REST commands instead of using an SDK; the call returns a JSON payload with the data.

Let's see how we can fetch SharePoint List Items using a simple HTTP REST command. The REST method to call is called GetListItemEx. Let's first look at a raw HTTP command that you can send using Postman for example. There are a few variables to change, which we will review.

GET ENZO_URI/bsc/sharepoint/getlistitemsex HTTP/1.1
authToken: YOUR_AUTH_TOKEN
_config: myconfigname
viewname: mylist
where: State='FL'

The following variables should be replaced in the above code:

  • ENZO_URI: this is the URI of your Enzo service endpoint that is assigned to you on the portal
  • YOUT_AUTH_TOKEN: this is your assigned authToken, also available on the portal
  • myconfigname: this is a configuration name that you created in the portal that points to SharePoint
  • viewname: the name of the SharePoint list
  • where: an optional WHERE clause that looks like a SQL where clause

For example, the following Postman screenshot shows you the REST command I sent to my server, which in turn connected to SharePoint Online to fetch items from the US States list. The name of the configuration is called sharepointroggero (we will see this shortly).

Fetching SharePoint List Items Using A Simple HTTP REST Command 

As you can see, there are no SharePoint-specific secrets here; all the details are stored on the portal under the configuration setting called sharepointroggero. Let’s go to the portal and review the configuration settings; once you log in to the portal, click on the SharePoint service on the left, and click on Create. You will see a screen similar to this where you can store your configuration settings.

Fetching SharePoint List Items Using A Simple HTTP REST Command 

Now let’s create a small C# Console project to make the same REST call. To try the following source code, you will need to sign up on the Enzo Online portal here, create a configuration setting for SharePoint Online and access your Enzo URI and AuthToken by selecting Enzo Accounts from the menu. The code does essentially the same thing as above: it retrieves the content of a list called MyList using a configuration setting called myconfigname. As discussed previously, this code does not use the SharePoint SDK; it relies entirely on HTTPS REST calls.

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Net;  
  5. using System.Text;  
  6. using System.Threading.Tasks;  
  7.   
  8. namespace Sample  
  9. {  
  10. class Program  
  11. {  
  12. static void Main(string[] args)  
  13. {  
  14.     string url = "https://ENZO_URI/bsc/sharepoint/getlistitemsex";  
  15.     string authId = "YOUR_AUTH_ID";  
  16.     WebRequest wr = WebRequest.CreateHttp(url);  
  17.     try  
  18.     {  
  19.         // Add the required HTTP headers for the call  
  20.         wr.Headers.Add("authToken", authId);  
  21.         wr.Headers.Add("viewname""mylist");  
  22.         wr.Headers.Add("_config""myconfigname");  
  23.         wr.Method = "GET";  
  24.         var resp = wr.GetResponse();    // Execute the command  
  25.         using (var stream = resp.GetResponseStream())  
  26.         {  
  27.         }  
  28.         Console.WriteLine("HTTP Response: " + ((System.Net.HttpWebResponse)(resp)).StatusCode);  
  29.   
  30.     }  
  31.     catch (Exception ex)  
  32.     {  
  33.         Console.WriteLine("ERROR: Response from " + baseUrl + command + ":" + ex.Message);  
  34.     }  
  35.     Console.ReadKey();  
  36. }  
  37. }  
  38. }  

Similarly, here is a Python sample code that does essentially the same thing.

  1. import sys  
  2. import urllib  
  3. import urllib2  
  4. import requests  
  5.   
  6. enzourl_receiveMsg="https://ENZO_URI:ENZO_PORT/bsc/sharepoint/getlistitemsex"  
  7. enzo_guid="YOUR_AUTH_ID"  
  8.  
  9. #create the headers this call expects  
  10. headers={  
  11.     'authToken': enzoguid,  
  12.     'viewname''mylist',  
  13.     '_config''myconfigname'    
  14. }  
  15. response=requests.get(enzourl_receiveMsg,headers=headers)  

The purpose of this article was to introduce you to a new development approach that simplifies development, and removes complex SDKs from client code using SharePoint as an example. Additional documentation and sample code is available online.