I can't find the DRIVE-ITEM-ID

Copper Contributor

Hello how are you?

 

I managed the most complicated steps that would be authentication, but what I believed to be the easiest became an even greater challenge.

 

When I access the graph developer
https://developer.microsoft.com/en-us/graph/graph-explorer. I can't get to a specific excel sheet. I tried in several ways, I got the driveId,l driveItem, but the Drive-Item-Id I can't find at all.

 

Even the file that I actually need to work I can't reach, only when I go to the "My recent files" endpoint.

 

Would anyone have a suggestion on how to get the DRIVE-ITEM-ID of an excel sheet?

 

I created an application, because the objective is to develop a web application in Python to connect our automations and this also involves connecting several APIs.

 

Can anyone give me some help?

2 Replies

@carvalhodouglaspereira please check the queries below and see which one will help you. If you already have the drives id then you can use the children property to navigate to the excel workbook you are looking for. Remember to specify the strings in single quotes when subtituting where-object with $filter query e.g 

https://graph.microsoft.com/v1.0/drives?$filter=createdBy/user/email eq '<your-email>' 

And also make sure you have the requisite permissions as documented List Drives - Microsoft Graph v1.0 | Microsoft Docs

$drive = <Invoke graph endpoint> -Uri "drives" |
    Where-Object { $_.createdBy.user.email -eq $user.email } |
    Select-Object -First 1

$demoFilesFolder = <Invoke graph endpoint> -Uri "drives/$($drive.id)/root/children" |
    Where-Object { $_.name -eq "Demo Files" } |
    Select-Object -First 1 #optional

$driveItem = <Invoke graph endpoint> -Uri "drives/$($drive.id)/items/$($demoFilesFolder.id)/children" |
    Where-Object { $_.name -eq "your-workbookname.xlsx" } |
    Select-Object -First 1 #optional

 

Here are more endpoints that could be of use to you
# Use this endpoint to upload an excel workbook that already exists.
$driveItem = <Request-Resource-with-delegated-perms> -Uri "me/drive/root:/$($uploadFileName):/content" -Method "PUT" -FilePath $workbookFilePath -PermissionNeeded "Files.ReadWrite.All"

# NB: In above no need to check the existence of driveItem, as it will be created if it does not exist
# if it exists, it will just generate a new version.

$worksheet = <Request-Resource-with-delegated-perms> -Uri "me/drive/items/$($driveItem.id)/workbook/worksheets" -PermissionNeeded "Files.Read" |
Where-Object { $_.name -eq "Sheet1" } |
Select-Object -First 1

$driveItemWorkbookTable = <Request-Resource-with-delegated-perms> -Uri "me/drive/items/$($driveItem.id)/workbook/tables" -PermissionNeeded "Files.Read" |
Where-Object { $_.name -eq "Table1" } |
Select-Object -First 1

$tableColumn = <Request-Resource-with-delegated-perms> -Uri "me/drive/items/$($driveItem.id)/workbook/tables/$($driveItemWorkbookTable.id)/columns" -PermissionNeeded "Files.Read" |
Select-Object -First 1

$tableRow = <Request-Resource-with-delegated-perms> -Uri "me/drive/items/$($driveItem.id)/workbook/tables/$($driveItemWorkbookTable.id)/rows" -PermissionNeeded "Files.Read" |
Select-Object -First 1