I am trying to upload files to a SharePoint site using MS Graph API in Python. I am able to generate the access-token and the site-id. However, when trying to generate the drive-id using the access-token and site-id, I am getting the below error:
{‘error’: {‘code’: ‘itemNotFound’, ‘message’: ‘Requested site could not be found’, ‘innerError’: {‘date’: ‘2024-06-14T07:46:41’, ‘request-id’: ‘8e4d9b47-c827-448a-8**’, ‘client-request-id’: ‘8e4d9b47-c827-448a-86***’}}}*
The site I am trying to connect to does exist.
I have the “Sites.ReadWrite.All” permission for Microsoft Graph and Sharepoint.
Below is the function I am using to get the drive-id:
`def get_drive_id(site_id, access_token):
headers = {
'Authorization': access_token
}
url = 'https://graph.microsoft.com/v1.0/sites/{}/drives'.format(site_id)
response = get(
url,
headers=headers
)
json_response = response.json()
drive_id = json_response['value'][0]['id']
print("drive_id: {}".format(drive_id))
return drive_id
`
The same API call is running successfully in Postman.