How retrieve all files from sharepoint document library - "Shared Documents" based on last modified date using Graph API?

VIPPALA MADHAVA REDDY 45 Reputation points
2023-11-09T16:56:43.5266667+00:00

Requirement

Get all the files from the Sharepoint folders recursively (including sub-folders at all levels) that were modified after a specific date, using Graph API.

I have tried different methods, but none worked as expected. I am able to achieve a little progress with the below procedure but got an error- tooManyResources.

Steps I followed:

Following the below procedure, I am able to get files from Teams Wiki Data document library (list type), but the same is not working for Shared Documents it is giving this error code - tooManyResources.

  • https://graph.microsoft.com/v1.0/sites/<site-id>/lists/ - get all lists of the site.
  • There are two document library type lists in the response - Teams Wiki Data and Shared Documents. Noted ids of both the lists.
  • https://graph.microsoft.com/v1.0/sites/<site_id>/lists/<list_id>/items - used this without any query parameters and able to see results.
  • For the Shared Documents library, I can see all the results from sub-folders also. For Teams Wiki Data few items are returned, I'm not sure why it so, maybe it has only few items in it.
  • Again now, added these query parameters to the request.

Query Parameters

{
    "Prefer": "HonorNonIndexedQueriesWarningMayFailRandomly",
    "$filter": "fields/Modified ge '2022-03-08T08:23:03Z'"
}
  • For Teams Wiki Data it gives a convincing response. No errors and I can see some documents and folders.
  • But for Shared Documents, the same request gives following error-

Error Response

{'code': 'notSupported',
 'innerError': {'client-request-id': '<>',
                'code': 'tooManyResources',
                'date': '2023-11-09T16:12:13',
                'request-id': '<>'},
 'message': 'The request is unprocessable because it uses too many resources'}
  • On updating query parameters as below, gives a different error.
{
    "Prefer": "HonorNonIndexedQueriesWarningMayFailRandomly",
    "$filter": "lastModifiedDateTime ge '2022-03-08T08:23:03Z'"
}

Error

{
    "error": {
        "code": "BadRequest",
        "message": "Invalid filter clause: A binary operator with incompatible types was detected. Found operand types 'Edm.DateTimeOffset' and 'Edm.String' for operator kind 'GreaterThanOrEqual'.",
        "innerError": {
            "date": "2023-11-09T17:55:52",
            "request-id": "<>",
            "client-request-id": "<>"
        }
    }
}

Conclusion

  • Please let me know, if any workaround to resolve the above errors - tooManyResources and BadRequest - incompatible types.
  • Please suggest any other possible ways to achieve the aforementioned requirement using Graph API (preferred or any better alternative)

References

Thanks in advance.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,081 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,726 questions
SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,615 questions
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 35,711 Reputation points Microsoft Vendor
    2023-11-10T02:22:55.5666667+00:00

    Hi @VIPPALA MADHAVA REDDY,

    Per my test, you could use following search api to get files by date.

    POST /search/query
    Content-Type: application/json
    
    {
      "requests": [
        {
          "entityTypes": [
            "driveItem"
          ],
          "query": {
    "queryString":"path:\"https://xxx.sharepoint.com/sites/xx/Shared%20Documents/\" AND LastModifiedTime < date"
          }
        }
      ]
    }
    

    SPOSearch


    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.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.