You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As stated in the title I wish to understand, using the Python SDK, how can I use the update API documented here
My example code so far:
# PATCH /drives/{drive_id}/root:/{file_path}:/list_item
async def aupdate_file_metadata(
self,
drive_item_id: Optional[str] = None,
drive_item_path: Optional[str] = None,
title: Optional[str] = None,
description: Optional[str] = None,
drive_id: Optional[str] = None,
):
"""
Update the metadata (Title, Description) of a file in OneDrive/SharePoint.
:param drive_item_id: The ID of the file to update. Either this or drive_item_path param is required.
:param drive_item_path: the path of the file to update. Either this or drive_item_id param is required.
:param title: The title to set for the file.
:param description: The description to set for the file.
:param drive_id: The ID of the OneDrive/SharePoint drive where the file is located.
"""
if drive_id is None:
drive_id = self.drive_id
if drive_item_path is None and drive_item_id is None:
raise ValueError("At least drive_item_path or drive_item_id is required")
item_id = f"root:{drive_item_path}:"
item_id = drive_item_id if drive_item_id else item_id
# Create metadata update payload
metadata_payload = {"fields": {}}
if title:
metadata_payload["fields"]["Title"] = title
if description:
metadata_payload["fields"]["Description"] = description
if not metadata_payload["fields"]:
logger.warning("No metadata provided to update.")
return None
try:
# Update metadata using PATCH request
updated_metadata = await self.client.drives.by_drive_id(drive_id).items.by_drive_item_id(item_id).list_item.patch(metadata_payload)
return updated_metadata
except ODataError as e:
logger.error(f"Error updating metadata for file '{drive_item_id}': {e}")
except Exception as ex:
logger.error(f"Unexpected error: {ex}")
The example in the documentation update a driveItem entity, where in my use case I believe I have to reference the listItem in order to update the associated field metadata which I believe is the dict containted the columns metadata displayed in the SharePoint storage library dashboard. The ListItemRequestBuilder seems not to have a patch method.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
As stated in the title I wish to understand, using the Python SDK, how can I use the update API documented here
My example code so far:
The example in the documentation update a
driveItem
entity, where in my use case I believe I have to reference thelistItem
in order to update the associatedfield
metadata which I believe is the dict containted the columns metadata displayed in the SharePoint storage library dashboard. TheListItemRequestBuilder
seems not to have apatch
method.Beta Was this translation helpful? Give feedback.
All reactions