1

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.

Jurgen Strydom
  • 3,540
  • 1
  • 23
  • 30
Danielakaws
  • 37
  • 1
  • 4

1 Answers1

0

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

Neel Shah
  • 81
  • 1
  • 7
  • 1
    I have finally solved it. The URL indeed was wrong, the correct one was `URL='https://graph.microsoft.com/vxx/sites/sharepointsite:/sites/site:/lists/list id/items'`. Also, the way I was uploading the JSON was wrong. To generate a valid JSON I had to take each line individually from the panda dataframe, convert it to a proper format and then do a POST operation for each line in the following way: `requests.post( URL, headers={'Authorization': 'Bearer ' + token['access_token'] , 'content-type': 'application/json'}, json=data, )` Kindly appreciate your help. – Danielakaws May 07 '21 at 07:54