Search code examples
microsoft-graph-apioffice365apiexcel-online

Corrupted workbook created, when trying to create one using ms-graph APIs


I am trying to create a new Workbook inside my OneDrive, using the following API call :

HTTP request:

POST https://graph.microsoft.com/v1.0/me/drive/root:/<path>:/children
Content-Type: application/json

{
  "name": "NewBook.xlsx",
  "file": { },
  "@microsoft.graph.conflictBehavior": "rename"
}

This creates a new workbook in the one drive.
But, when I try to open it (from the OneDrive UI), it shows that the excel file is corrupted.
Contrary to that, when I try to create a new .txt or .pptx or .docx and then try to access that, it is easily accessible.
The API call that I am making here, is not present in the official MS-Graph API reference. It was a hit and trial done, and it worked. But the file being created is corrupted only in case of Excel.

  • If the creation of workbook is not allowed, can anyone provide me with the links as to where it is officially mentioned?
  • If its allowed, then what changes do i need to make in the current API call?

Solution

  • I've finally found a way to create a workbook using ms-graph-api. Although creation of workbook is not allowed, i did a bit of tweaking, to create a new workbook with the specific name.

    1) Using Apache POI, created a new workbook locally.
    2) Uploaded the workbook, with the specified name.