“I’m using the Office actions in my Power Automate flow, but they don’t accept the environment variable, how do I get this source and drive id?”
When using SharePoint as a data storage, most of the actions ask simply for the SharePoint site url and the document library id. Two pieces of information you can use the environment variables for. But some of the actions, more specifically the Office actions won’t accept them. They’re asking for a ‘drive’, not url.
“The provided drive id appears to be malformed, or does not represent a valid drive.”

A small peek into the code of a manually configured action will tell you why. They don’t ask for SP url, library id, nor file id. They want the source, drive, and file id used in Graph API. But where do you get them? What’s the easiest, least complicated approach?
Get the source and drive using a ‘dummy’ action
Looking at the screenshot above, you might get an idea about the most accessible place. It’s from the action itself where you select from the choices and ‘peek code’. You can take all the id’s from there and store them in a text or JSON environment variables.
Location = source
e.g.
sites/tomrihacom.sharepoint.com,f8af73f6-ed19-489a-b5e0-8b425608c4a9,8b0ef18d-5037-4622-9d72-5fd14eff44b5
Document Library = drive
e.g.
b!9nOv-Bntmki14ItCVgjEqY3xDos3UCJGnXJf0U7_RLXGUPMft4BURL-nXLZiZlxk
File = file
e.g.
01VQXPVKXU4RD2WKXYTJCYUO7A3AJDOUJY
Those are the id’s you can use not only in the Power Automate actions, but in Graph API requests too!
Get the file id from its properties
The SharePoint site and document library are often fixed, but the file might change. That’s why the ‘peek code’ is not a solution in this case – dynamic files need a different approach.
The easiest one is to just enter the file name starting with /, e.g.
/HTTP requests to Graph API cheatsheet.docx
and if it’s in a folder, add the folder path too:
/Word files/HTTP requests to Graph API cheatsheet.docx

But if you really want the file id, if you’re not happy with just the name, the ‘Get file properties’ action will provide it. Search for the specific file in the library using ‘Get files (properties only)’, e.g. by file name and once you find it get its properties.
Among these properties will be the Drive item ID – the file id you’re looking for.

Get the SP source and drive id through Graph API
Another way to get this information is through Graph API, and it requires a bit more coding to get the same results. That’s why I’ll go just quickly through the requests, all of which you can try in Graph Explorer by yourself.
Find a SharePoint site by the name:
https://graph.microsoft.com/v1.0/sites?search=<siteName>
You’ll get the site id in the outputs.

Use the id to list all libraries (= drives).
https://graph.microsoft.com/v1.0/sites/<siteId>/drives
You’ll get the list of all libraries on the site, use their ‘name’ to find the desired ‘id’.

The specific file can be then accessed using the path + file name in the library.
https://graph.microsoft.com/v1.0/sites/<siteId>/drives/<driveId>/root:<filePath>
You’ll get the file id, link to the file, download url, and much more.

Summary
Working with the Office actions in Power Automate requires a different approach than the actions dedicated to SharePoint. They use Graph API to connect to the data sources, and as such they need different types of identifiers. More specifically the SP source and drive id, and the path to the file.
This article explained two approaches how to get them. The first one uses the flow designer to get the source and drive id for files in SP – select them from a dropdown, peek code, and take it from there. No need for any coding, and if the difference is only between the DEV / TEST / PROD environments it’s good enough. Do it once on each environment and store the ids in environment variables.
The second one covers Graph API – if you’re looking for something more dynamic, if the sites and libraries can change, that’s the right approach. You’ll still need a few variables to store the names used for filtering, but you’ll get everything else from the API.