Uppload data from JSON to Sharepoint List with Microsoft Graph API in Python

986 Views Asked by At

I am trying to add some data from a JSON file that has the same structure as a goal SharePoint list. I have previously checked that I can access the list with a get method and that I can authenticate and get the token. The problem is that I can't seem to figure out how to properly do the data upload.

Below is my simplified code

URL= 'https://graph.microsoft.com/vx.x/sites/sharepointname/sites/group/lists/listId/rows/add'
json_file = a pandas file converted to json

post_data = requests.post( URL,
            headers={'Authorization': 'Bearer ' + token['access_token'], 'Content-Type': 'application/json'},
            data = json_file
            )

This does not work, some of the errors I got are "Resource not found for the segment \uxxxrows\uxxx." I would be very grateful for any help.

1

There are 1 best solutions below

1
On BEST ANSWER

I think you might have gotten the URL wrong. That would explain the Resource not found for the segment... error you are encountering.

If you are trying to create a new list, here's the documentation
URL - POST https://graph.microsoft.com/v1.0/sites/{site-id}/lists

And if you are trying to add an item to an existing list, here's the documentation
URL - POST https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items