MS Graph: Creating an excel Workbook

Mercy Muchai 1 Reputation point
2022-08-22T11:43:25.08+00:00

I'd like to create an excel workbook. When running the POST endpoint to create a workbook:

https://developer.microsoft.com/en-us/graph/graph-explorer?request=workbooks&method=POST&version=v1.0&GraphUrl=https://graph.microsoft.com

I get a 400 as shown below

{ "error": { "code": "BadRequest", "message": "Resource not found for the segment 'workbooks'.", "innerError": { "date": "2022-08-22T11:39:32", "request-id": "c1a9e450-a7b0-4f78-bc4f-c270deaf60ac", "client-request-id": "dc021ab9-5c0b-f03c-76c0-b1f279225f0f" } } }.

The documentation for workbooks here does not also outline the endpoint and how to run the query.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,446 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Sheena-MSFT 1,731 Reputation points
    2022-08-22T12:22:23.017+00:00

    Hi @ MercyMuchai-8764,

    Currently it is not supported to create an excel workbook using workbook resource. It only allow reading and modifying workbook that are already exist.

    As a workaround you can create an empty excel using the following Graph query:

    PUT https://graph.microsoft.com/me/drive/root:/File.xlsx:/content  
    

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.

    0 comments No comments

  2. Mercy Muchai 1 Reputation point
    2022-08-23T08:18:11.25+00:00

    I'm not sure this created the workbook in the right format. When I run PUT, the workbook is created but cannot be opened due to this error.

    PUT https://graph.microsoft.com/v1.0/me/drive/root:/MyShop.xlsx:/content

    I observe it does not have any worksheets by default. Curious if the PUT should have a body that adds in some of that. Output when trying to create a new worksheet in it:

    {  
        "error": {  
            "code": "MetroFileFormatMismatch",  
            "message": "This workbook couldn't be opened because the file format may not be matching with the file extension.",  
            "innerError": {  
                "code": "unsupportedWorkbook",  
                "message": "The request failed. The workbook contains unsupported features or exceeds the size limit.",  
                "innerError": {  
                    "code": "MetroFileFormatMismatch",  
                    "message": "This workbook couldn't be opened because the file format may not be matching with the file extension."  
                },  
                "date": "2022-08-23T08:09:54",  
                "request-id": "**",  
                "client-request-id": "**"  
            }  
        }  
    }  
    

    When I try to manually open it, I get the same error:

    234001-image.png