python me.drive - create folders, add files, update files
I'm trying to use the msgraph-sdk for python. I followed the python tutorial easily. I want to add functionality to the tutorial, https://learn.microsoft.com/en-us/graph/tutorials/python-extend-app.
I would like to make calls for:
- List items listed in my drive:
https://graph.microsoft.com/v1.0/me/drive/root/children - Create a folder in my drive:
https://developer.microsoft.com/graph/graph-explorer?request=me%2Fdrive%2Froot%2Fchildren&method=POST&version=v1.0&GraphUrl=https://graph.microsoft.com&requestBody=eyJuYW1lIjoiTmV3IEZvbGRlciIsImZvbGRlciI6e319&headers=W3sibmFtZSI6IkNvbnRlbnQtdHlwZSIsInZhbHVlIjoiYXBwbGljYXRpb24vanNvbiJ9XQ== - Create a new empty text file
- Update text file with new content
I can run the REST calls for these with no problem. When I try to use the msgraph-sdk for python using the code snippets, it doesn't work or the code snippets are incomplete compared to the REST API examples.
For example, "List items listed in my drive":
The python code snippet provided is:
from msgraph import GraphServiceClient
result = await graph_client.drives.by_drive_id('drive-id').items.by_drive_item_id('driveItem-id').children.get()
This assumes I have the drive-id and drivItem-id. I don't have these. So I thought I would try going through .me.drive in the example below...
I found examples of accessing the current user my drive by:
result = await graph_client.me.drive.get()
This returns an error:
msgraph.generated.models.o_data_errors.o_data_error.ODataError: APIError Code: 404 message: None error: MainError(additional_data={}, code='itemNotFound', details=None, inner_error=InnerError(additional_data={}, client_request_id='removed_for_this_qa', odata_type=None, request_id='removed_for_this_qa'), message='Item not found', target=None)
If I runt the REST API to get the drive-id and drivItem-id and use it in
result = await graph_client.drives.by_drive_id('drive-id').items.by_drive_item_id('driveItem-id').children.get()
Then I get an "access denied", even though I have authenticated for myself.
Is the msgraph-sdk incomplete? Should I use REST instead? Are their better documentation for python msgraph-sdk that is up to date with examples for basics like what I have outlined here?
Thanks,
Mark Thielen