I have a question around the topic of reading SharePoint lists programmatically.
- The code I've written is using app level authentication.
- I am able to read items from some lists of the same SharePoint site but not others.
I think there's an issue that is related to the configuration of the permissions on the site and I wanted to know if anyone could share any thoughts around this issue.
I am at a point where I might just re-create a list myself instead of reading the one that already exists because I am not sure how to resolve this issue otherwise.
Any help would be greatly appreciated ! Thanks
def test_get_ibrx_it_list_count(self, office_service):
"""assert ibrx-it list count is greater than zero"""
base_url = 'https://omitted.sharepoint.com/sites/example/'
ctx = office_service.set_client_context(base_url)
def print_progress(items):
"""
:type items: office365.sharepoint.listitems.collection.ListItemCollection
"""
print("Items read: {0}".format(len(items)))
def get_total_count(target_list):
"""
:type target_list: office365.sharepoint.lists.list.List
"""
# all_items = target_list.items.top(50).get().execute_query()
# all_items = target_list.items.get_all(500).execute_query()
all_items = target_list.items.get_all(50, print_progress).execute_query()
print("Total items count: {0}".format(len(all_items)))
return len(all_items)
# this list is empty as of 221227 -- this list exists and does NOT return items.
# sharepoint_list = ctx.web.lists.get_by_title("IT Provisioning Request")
# this list is NOT empty as of 221227 -- this list exists and it returns items.
# sharepoint_list = ctx.web.lists.get_by_title("IT Employee List")
# create by my user, and it returns a list of items. -- this list exists and it returns items.
sharepoint_list = ctx.web.lists.get_by_title("Test List")
count = get_total_count(sharepoint_list)
assert count > 0
This code works if I'm attempting to read a list that I've created on the SharePoint site. It also works for a pre-existing list on the SharePoint site of which I did not create. However, there are some lists that I did not create on the SharePoint site which I did not create that it can't read. I'm not sure why it's able to read some lists but not others on the same SharePoint site.