๐Power Automate Blog Post: Extract Library Name and Library ID from "When a file is created (properties only)" Trigger
๐ Power Automate Blog Post: Extract Library Name and Library ID from "When a file is created (properties only)" Trigger
In this guide, we’ll walk through building a robust Power Automate flow that:
-
Works with the “When a file is created (properties only)” trigger.
-
Dynamically extracts both Library Name and Library ID (GUID).
-
Avoids unreliable URL parsing.
-
Uses SharePoint REST API for accurate library details.
๐ฏ Scenario
You want a flow that triggers automatically when a new file is uploaded to any SharePoint document library and retrieves:
-
The correct Library Name.
-
The accurate Library ID (GUID).
๐น Full Step-by-Step Solution
1️⃣ Trigger: "When a file is created (properties only)"
-
Configure:
-
Site Address: Your SharePoint site.
-
Library Name: Specify a library or leave blank for all libraries.
-
This trigger provides metadata such as:
-
{Link}(file URL) -
{Path}(relative path)
2️⃣ Compose: File URL
-
Name:
Compose_FileURL -
Expression:
triggerOutputs()?['body/{Link}']
✅ Captures the full file URL.
3️⃣ Compose: Relative Path
-
Name:
Compose_RelativePath -
Expression:
triggerOutputs()?['body/{Path}']
✅ Retrieves the relative path like LibraryName/folder/file.docx.
4️⃣ Compose: Library Name
-
Name:
Compose_LibraryName -
Expression:
first(split(outputs('Compose_RelativePath'), '/'))
✅ Dynamically extracts the first segment of the path as the library name.
5️⃣ Send an HTTP request to SharePoint
-
Action:
Send an HTTP request to SharePoint -
Site Address: Same site as trigger.
-
Method:
GET -
URI:
_api/web/lists/getByTitle('@{outputs('Compose_LibraryName')}')?$select=Id,Title
✅ Dynamically retrieves Library metadata by name.
6️⃣ Parse JSON: Parse HTTP response
-
Content:
Body from HTTP request -
Schema:
{ "type": "object", "properties": { "d": { "type": "object", "properties": { "Id": { "type": "string" }, "Title": { "type": "string" } } } } }
✅ Parses the response to easily access Id and Title fields.
7️⃣ Compose: Library ID
-
Name:
Compose_LibraryID -
Expression:
outputs('Parse_JSON')?['d']?['Id']
✅ Extracts the correct Library ID (GUID) from the parsed JSON response.
๐ Key Benefits
-
No hardcoding of library names or IDs.
-
Works for any document library dynamically.
-
Reliable and API-driven.
-
Avoids fragile parsing of URL query strings.
๐น Summary of Key Expressions
| Step | Expression |
|---|---|
| Compose_FileURL | triggerOutputs()?['body/{Link}'] |
| Compose_RelativePath | triggerOutputs()?['body/{Path}'] |
| Compose_LibraryName | first(split(outputs('Compose_RelativePath'), '/')) |
| Compose_LibraryID | outputs('Parse_JSON')?['d']?['Id'] |
✅ This solution ensures your Power Automate flow is dynamic, reliable, and production-ready when working with the “When a file is created” trigger in SharePoint.
๐ Want this packaged as a ready-to-import .zip template? Just ask! ๐
Comments
Post a Comment