Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FilterDate option in ChangeQuery #833

Open
ssmails opened this issue Feb 27, 2024 · 1 comment
Open

FilterDate option in ChangeQuery #833

ssmails opened this issue Feb 27, 2024 · 1 comment
Labels

Comments

@ssmails
Copy link

ssmails commented Feb 27, 2024

Referring to #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()
)
@vgrem vgrem added the question label Mar 4, 2024
@mmcgugan
Copy link

mmcgugan commented Apr 2, 2024

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants