Working with List Items
A list item is a single row in a SharePoint list or library.
Items store data in fields (columns) and have a numeric ID unique
within their list.
Prerequisites
| Requirement |
Description |
Reference |
| Site Owner or Member role on the list |
Required to create, update, and delete items. Read access for queries. |
SharePoint permissions |
Getting started
from office365.sharepoint.client_context import ClientContext
ctx = ClientContext("https://contoso.sharepoint.com/sites/team").with_client_certificate(
"contoso.onmicrosoft.com", client_id="client_id", thumbprint="thumbprint", cert_path="./cert.pem"
)
target_list = ctx.web.lists.get_by_title("Documents")
# Read all items
items = target_list.items.get().execute_query()
for item in items:
print(f" {item.id}: {item.properties.get('Title', '')}")
# Create an item
item = target_list.add_item({"Title": "New report"}).execute_query()
print(f"Created: {item.id}")
Create, Update & Delete
| What |
File |
Notes |
| Create item |
create.py |
Single item with field values |
| Create in bulk |
create_bulk.py |
Many items via a single $batch request |
| Update item |
update.py |
Change one or more fields |
| Update in bulk |
update_bulk.py |
Many updates in a single $batch request |
| Delete item |
delete.py |
Remove an item |
| Delete in bulk |
delete_bulk.py |
Remove many items in a single $batch request |
Read & Query
Lookup & Field Values
Attachments
Versions
API reference