SureshS-9649 avatar image
0 Votes"
SureshS-9649 asked RaytheonXie-MSFT commented

Get ListItems not getting the items using SharePoint AppOnly Authentication

Hi All,

I am using App only SharePoint AppOnly Authentication. I have created "ClientID and Client Secret ID" as well. Based on that, I can authenticate the using the below and trying to get the document library list items but the below code returning 0 count. Please suggest me to resolve this issue.

var ctx = new OfficeDevPnP.Core.AuthenticationManager().GetAppOnlyAuthenticatedContext(repositoryUrl, "fsfsd-sdsdsf-353453-sdgsds", "vsdsdUOUnklglkn=sdgsgdUTIUTIISDSDGsdgsPOP=");

Site site = ctx.Site;

             Microsoft.SharePoint.Client.ListItemCollection listitems = null;
             Microsoft.SharePoint.Client.List docList = ctx.Web.Lists.GetByTitle("Test Lib");

             List<Microsoft.SharePoint.Client.ListItem> items = new List<Microsoft.SharePoint.Client.ListItem>();
             int i = 0;
             ListItemCollectionPosition position = null;
             int rowLimit = 0;
             var camlQuery = new CamlQuery();
             camlQuery.ViewXml = @"<View><Query><OrderBy Override=""TRUE""><FieldRef Name='ID'/></OrderBy></Query><RowLimit Paged=""TRUE"">" + rowLimit + "</RowLimit></View>";
             camlQuery.FolderServerRelativeUrl = docList.RootFolder.ServerRelativeUrl + "/" + "2000/O003";
             camlQuery.ListItemCollectionPosition = position;
             listitems = docList.GetItems(camlQuery);
             position = listitems.ListItemCollectionPosition;

Thanks & Regards
Suresh S

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

RaytheonXie-MSFT avatar image
0 Votes"
RaytheonXie-MSFT answered RaytheonXie-MSFT commented

Hi @SureshS-9649 ,
Per my test,The issue occurs when we didn't grant enough permission.We have authenticate the site but still don't have the permission to the list.I suggest to set full control of the site collection or Website.
Please try following App's Permission Request XML in the url

 <AppPermissionRequests AllowAppOnlyPolicy="true">
   <AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="FullControl" />

Please refer to the following link

If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @SureshS-9649 ,
I am checking to see if the problem has been resolved.

0 Votes 0 ·

Hi @SureshS-9649 ,
If there's anything you'd like to know, don't hesitate to ask.

0 Votes 0 ·

Hi @SureshS-9649 ,
would you please provide us with an update on the status of your issue?

0 Votes 0 ·