Recently performed operations on files and directories are not reflecting in API

Vivek Kumar 1 Reputation point
2022-05-17T06:06:42.663+00:00

I am working on a project where i need to list files from the SharePoint sites. It's working fine when files are already there on the SharePoint site. But when we have recent actions on files like Added/Deleted/Updated then it takes time to reflect these changes in the API.
For example: if we delete files from SharePoint then it still displays those files in API for several minutes or sometimes for a day.
This seems inconsistence. What I need, If there are any changes on SharePoint files and folders then it should reflect immediately.

Can someone please help me if I am doing something wrong.
Thanks

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,582 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,668 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Tong Zhang_MSFT 9,116 Reputation points
    2022-05-17T09:34:34.607+00:00

    Hi @Vivek Kumar ,

    Are you using the graph api or the rest api? Based on my research and testing, you can use the following API to list files from SharePoint sites, In my test , if I delete/create SharePoint files ,it will reflect immediately. Hope it can help you .

    Graph API:

    GET  https://graph.microsoft.com/v1.0/sites('site-id')/lists('list-id')/items  
    

    Rest API:

    GET   /_api/web/GetFolderByServerRelativeUrl('/sites/xxx/listname')/Files  
    

    More information for reference:

    Rest API: https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-folders-and-files-with-rest#working-with-files-by-using-rest

    Graph API: https://learn.microsoft.com/en-us/graph/api/listitem-list?view=graph-rest-1.0&tabs=http#http-request


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.