Home » excel » excel – 403 Forbidden on reading CSV file in OneDrive

excel – 403 Forbidden on reading CSV file in OneDrive

Posted by: admin May 14, 2020 Leave a comment

Questions:

I am trying to read my CSV files using Microsoft Graph API:

/me/drive/items/${someId}/workbook/worksheets('${someSheetName}')/usedRange

However it returns

403 Forbidden -> AccessDenied -> Could not get WAC token.

When reading a XLSX file, it works fine. I am using personal microsoft account.

Thanks for your help.

How to&Answers:

CSV and .xls are not supported formats. Only .xlsx works for this feature.

Answer:

As others have pointed out, CSV files are not supported in the new Excel API. However, to help others who were initially confused by the error message like me, I’d like to elaborate a bit more.

First, it’s useful to distinguish the Microsoft Graph API and the Excel API. The Microsoft Graph API mostly provides the basic functionalities of a file storage system so that third-party can work with files and folders in OneDrive and SharePoint. The Excel API, on the other hand, provides Excel functionalities so that third-parties can work with Excel files (.xlsx files specifically). Although the Excel API uses the same resource identification system and shares the same request “syntax” as the Microsoft Graph API, the two are not the same.

The request below clearly belongs to the Excel API, not the Graph API. Although the Graph API can handle CSV file (it doesn’t care what type of file it’s working with since it’s application-agnostic), the Excel API can’t.

/me/drive/items/${someId}/workbook/worksheets('${someSheetName}')/usedRange

If you look at the endpoints in the Excel API, you’ll see that most of them point to features that do not exist in CSV files: workbook, worksheet, cells, etc. For instance, the request above attempts to read a specific worksheet within a workbook file, which is not possible if the file is CSV.

Also, the Excel API handles features such as formulas, data types, and cell formatting, which are also not present in CSV files.

Essentially, CSV files are no more than just plain-text files and thus are not supported by the Excel API.

Of course, it would be really helpful if the Excel API team could return a more meaningful error message. I personally find the current error message very misleading.