SharePoint List data access demo

I need to demonstrate reading data from SharePoint Online lists externally.

Setup the SharePoint tenant

     $srcsite = Connect-Site -url $srcurl -UserName "$AdminAccount" -Password $password
     $destsite = Connect-Site -url $desturl -UserName $o365Acct -Password $destpassword
     Copy-List -Name $destListName -SourceSite $srcsite -DestinationSite $destsite -InsaneMode
  • Check the list design using pnp- i.e check columns and datatypes
    Connect-PnPOnline -Url $SiteCollection -Credentials $Credentials 
    Get-PnPProvisioningTemplate -Out template.xml -Handlers Lists

Configure the App access


Then grant permissions to the app using the tenancy URI:
https://{tenant} and supply the clientid
Add the permissions xml, for reading lists..

<AppPermissionRequests AllowAppOnlyPolicy="true">  
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="Read"/>  
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web" Right="Read"/>  
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web/list" Right="Write"/>  

Re-use some managed code as depicted on the Patterns and Practices site

Whilst running that, use fiddler to get the bearer token.

Copy the bearer token to your the JavaScript Ajax snippet. Run the snippet from web server.

var siteurl = "https://{YOURTENANT}";  
            url: siteurl + "/_api/web/lists/getbytitle('Events')/items",
            method: "GET",
            headers: {
                "Accept": "application/json; odata=verbose",
                "authorization": "Bearer *{BEARER TOKEN HERE}* "
            success: function (data) {
                if (data.d.results.length > 0) {
                    console.log('in doSuccess');

                    for (var i = 0; i < data.d.results.length; i++) {
                        var item = data.d.results[i];
                        console.log(item.Title + item.Detail + item.br6c + item.m4eh);

            error: function (data) {
                alert("Error: " + data);


Obviously, this not a viable approach for the final application, but it does demonstrate how the endpoints, oAuth and REST work in order the interact with a SharePoint tenancy and its data. For the production solution, you will need to work with the proscribed mechanisms recommended by Microsoft.