pythonexcelmicrosoft-graph-apionedrive

Microsoft Graph API: 'ItemNotFound' Error When Accessing Excel File in OneDrive with Python in personal account


I am trying to read and update an Excel file stored in OneDrive using the Microsoft Graph API. However, I consistently encounter the following error: ERROR:root:Request failed: {"error":{"code":"ItemNotFound","message":"The requested resource doesn't exist.","innerError":{"code":"itemNotFound","message":"The requested resource doesn't exist.","date":"2025-01-18T22:20:58","request-id":"d908b11c-edcc-4a73-9383-2ca4328c3f4a","client-request-id":"d908b11c-edcc-4a73-9383-2ca4328c3f4a"}}}

Steps I Took

  1. I retrieved the file ID using the Microsoft Graph API's /drive/root/children endpoint.
  1. I verified that the file exists in my OneDrive account and is accessible.

  2. I used the correct API endpoint to access the workbook, for example: https://graph.microsoft.com/v1.0/me/drive/items/1555B702B0C2A00A!s86e7ed45f177405ba089286bc4cc00af/workbook/worksheets/Sheet1/range(address='A1:B2')

  3. I ensured the Microsoft Graph permissions are correctly configured:

What could cause the ItemNotFound error for a file that exists and is accessible via OneDrive?


Solution

  • In my case the issue was with the sheet names. I was using different sheet name with no spaces in in it when they had spaces. Please keep in mind that the message "The requested resource doesn't exist" doesn't always mean the id of the file is incorrect buy if the sheet name is incorrect it might also happen.