itemNotFound for file that does exist

Michael Millar 1 Reputation point
2021-02-03T12:27:14.553+00:00

I am setting user permissions (read or write) to files stored in OneDrive using the Graph API. The owner of the file is making the call to the API and the BaseURL for the request is in the form:

     https://graph.microsoft.com/v1.0/me/drive/root:/pathtofile/filename:/invite  

This works most of the time, but every now and then, the resource "isn't found" and I get a response like this:

     {  
        "error": {
          "code": "itemNotFound",
          "message": "The resource could not be found.",
          "innerError": {
            "date": "2021-02-01T12:19:21",
            "request-id": "ef47abe9-4576-4e14-930e-32638445c87c",
            "client-request-id": "ef47abe9-4576-4e14-930e-32638445c87c"
          }
        }
      }

The resource does exist. Sometimes a retry after a few seconds is successful, sometimes it doesn't seem to be successful for several minutes. This isn't good for users and any help resolving the issue / improving reliability would be gratefully received.

Regards,
Michael

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,907 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Diya Ahuja 5 Reputation points
    2023-06-30T18:07:28.0133333+00:00

    The issue you are experiencing is likely due to the fact that the resource is not always immediately available when the API call is made. This is because the resource may be in the process of being created or updated, and the API call is being made before the resource is ready.

    To improve reliability, you can try adding a delay before making the API call, or you can use the if-none-match request header to check if the resource has been updated since the last time the API call was made. If the resource has not been updated, the API will return a 304 Not Modified response, which can be used to avoid making unnecessary API calls.

    0 comments No comments