How to get SharePoint document library id by library name in Power Automate

Hello everyone and welcome to my blog. In today’s blog I will show how you can get SharePoint document Library Id by Library name, in a Power Automate flow.

Through my blog I share interesting tips and discuss on latest releases of Microsoft.NET technologies, Dynamics 365 and Power Platform, SharePoint and Client scripting libraries. Please subscribe to my blog to stay updated.

Let’s get started. I have document library – XRM in my site collection. I need to get the ID of the document library. Let’s see how we can do this in a Power Automate flow.

To start with, I will use a Power Automate flow with manual trigger. To query the document libraries in a site collection, I will use the ‘Send a HTTP request to SharePoint‘ action of the SharePoint connector.

Below illustration show the configuration of the action.

In the Site Address you need to select the site collection where your document library is there. The most important thing here is the Uri field. The Uri should be in the following format.

_api/v2.1/drives?$select=id,name&$filter=name eq '[document_library_name]'

You need to replace the document_library_name placeholder with the name of your document library. Below is the output when I execute the flow.

The id and name are available as value array item inside the body of the response. To get the id of the document library from the output, we need to use the below expression.

body('Send_an_HTTP_request_to_SharePoint').value[0].id

Send_an_HTTP_request_to_SharePoint is the action name. If you have renamed the action, you need to change this in the expression accordingly.

And that’s it. You should now have the document library id in the variable when you run the flow.

Hope this helped. For similar interesting topics on Microsoft.NET and Power platform, you can subscribe to my blog.

Debajit Dutta
Business Solutions MVP