[Python] How to format Graph API call to update Excel cell?

Discussão em 'Python' iniciado por Stack, Outubro 24, 2024.

  1. Stack

    Stack Membro Participativo

    I want to update an Excel cell value (hosted in SharePoint) using the Microsoft Graph API. Documentation is here.

    I have had success with other API calls (format updates, clearing cells) using a similar format as below, please help me understand what I'm doing wrong.

    In the code example I want to write "41373" to cell B:17 in sheet 'Plant_3'. The code example returns a 400 code error:

    "code": "InvalidAuthenticationToken",
    "message": "Access token is empty.",


    This message can be generic and mean the formatting of an API call is wrong rather than an authentication problem. Other Graph API calls work with the same ids and keys so I doubt it's an authentication issue.

    sheet = 'Plant_3'
    # get variables that work in other Graph API calls
    config_args=graph_config_params()
    # get Authorization Bearer token, again works in other Graph API calls.
    my_headers = set_up_ms_graph_authentication()
    url= f"https://graph.microsoft.com/v1.0/sites/{config_args['site_id']}/drives/{config_args['drive_id']}/items/{config_args['doc_id']}/workbook/worksheets/{sheet}/range/(address='B:17')"
    response = requests.patch(url,
    headers=my_headers,
    json={'values': [['41373']] })


    Things I've tried:

    • Switched keyword argument from json to data.
    • Single brackets / no brackets around '41373', both in json and data.
    • Verified permissions, removed Files.ReadWrite.All and got a 403 error.
    • Switched 'patch' to post and tried all configurations mentioned above.
    • Adding valueType argument: [['String']]

    Continue reading...

Compartilhe esta Página