Hello Janice Lehmann,
I understand you are trying to add rows to an Excel file saved in a SharePoint Document Library using Microsoft Graph, and yes, that can be done.
The main thing is to use the correct URL format for SharePoint. Instead of the OneDrive path, you’ll use something like this:
POST https://graph.microsoft.com/v1.0/sites/{site-id}/drives/{drive-id}/items/{item-id}/workbook/tables/{table-name}/rows/add
To fill in this URL, you’ll need a few IDs.
In my case, I have an Excel file named EmployeeData.xlsx
stored in the sridoclib document library of the "sridemosite" SharePoint site:
To get the SharePoint site ID, you can use this Graph API call:
GET https://graph.microsoft.com/v1.0/sites/root:/sites/<sitename>
Next, to get the document library (drive) ID, check this API call:
GET https://graph.microsoft.com/v1.0/sites/{site-id-from-above}/drives
Then, to get the Excel file's ID (item ID):
GET https://graph.microsoft.com/v1.0/sites/{site-id}/drives/{drive-id-from above}/root:/<filename>.xlsx
Once you have all of those, you can send data to the table inside the Excel file.
Here’s the request:
POST https://graph.microsoft.com/v1.0/sites/{site-id}/drives/{drive-id}/items/{item-id}/workbook/tables/{table-name}/rows/add { "index": null, "values": [ ["Sri", "Cloud"] ] }
Before running the API call, my Excel table looked like this:
After running the POST
call, the new row was added successfully:
You can refer to this Microsoft documentation to review the required permissions for this API call.
Hope this helps!
If this answer was helpful, please click "Accept the answer" and mark Yes
, as this can help other community members.
If you have any other questions or are still facing issues, feel free to post in the comments and I’ll be happy to assist further.