Office365-REST-Python-Client icon indicating copy to clipboard operation
Office365-REST-Python-Client copied to clipboard

FilterDate option in ChangeQuery

Open ssmails opened this issue 1 year ago • 1 comments

Referring to https://github.com/vgrem/Office365-REST-Python-Client/issues/821 @vgrem

Is there a plan to add a FilterDate option in the ChangeQuery or how can the filter query below be combined with ChangeQuery, so we can get the changes beyond a certain date ?

Currently, I use the below- but this does not return the deleted files. Looking for an option to get the created/updated/deleted file beyond a certain date. Also, for files that are manually deleted from the RecycleBin of sharepoint, will this query be able to report on those files as being deleted ?

items = (
    ctx.web.lists.get_by_title(doc_lib)
    .items.select(["FileSystemObjectType"]).filter("Modified gt '2024-02-10T08:23:03Z'").expand(["File", "Folder"])
    .get_all()
    .execute_query()
)

ssmails avatar Feb 27 '24 02:02 ssmails

You should be able to do that with change_token_start, but you have to create the token yourself. Maybe something like this:

from datetime import datetime
from office365.sharepoint.changes.query import ChangeQuery
from office365.sharepoint.changes.token import ChangeToken

since = datetime(2024, 2, 10, 8, 23, 3)
sp_list = ctx.lists.get_by_title(doc_lib).get().execute_query()
token = ChangeToken("1;3;{0};{1};-1".format(
    sp_list.id,
    int((since - datetime(1,1,1)).total_seconds() * 10**7),
))
query = ChangeQuery(
    item=True, list_=True,
    add=True, update=True, delete_object=True,
    change_token_start=ChangeToken(token),
)
changes = sp_list.get_changes(query).execute_query()

mmcgugan avatar Apr 02 '24 19:04 mmcgugan