Power Pages + Power Automate: Retrieve SharePoint Files via HTTP Trigger Flow - CloudFronts

Power Pages + Power Automate: Retrieve SharePoint Files via HTTP Trigger Flow

When building a Power Pages site to fetch SharePoint files, I initially relied on the official Power Pages flow trigger—“When Power Pages calls a flow.” However, the flow didn’t trigger reliably when initiated from the site. Despite proper configurations, the trigger wouldn’t execute consistently, leading to broken file fetch operations.

To overcome this, I replaced the unreliable trigger with a Power Automate flow using an HTTP request trigger. This method allowed me to invoke the flow through a JavaScript function executed on page load, passing the required record ID dynamically. The HTTP approach not only worked reliably but also gave me more control over the request and response.

This blog post outlines that workaround, from setting up the HTTP-triggered flow to integrating it seamlessly with Power Pages.

Background and the Problem

Power Pages provides a native trigger to call Power Automate flows. While ideal in theory, this approach often fails in practice due to:

  • Misconfigured permissions
  • Flow not included in a solution
  • Disabled integration settings
  • Environment or site mismatches

After spending time investigating these issues without consistent results, I decided to switch to a more controlled and universally reliable method using a HTTP trigger.

My Workaround – HTTP Trigger Flow

Power Automate Flow Setup:

Trigger:
Start with the “When an HTTP request is received” trigger. Define the request schema to accept a recordId— in this case, an orderId.

Compose (Request Variables):
Add a Compose action to extract the incoming ID.

List Rows – Document Locations:
Use DataverseList rows to retrieve the SharePoint Document Location related to the Order (based on the passed orderId). This assumes your files are stored in folders linked to Dataverse records.

Condition – Check If Folder Exists:
Use a Condition to check if any document location was found:

If record exists → proceed, If no records found → terminate the flow (folder doesn’t exist).

Compose – Relative URL:

first(outputs('List_rows')?['body/value'])?['relativeurl']

Compose – Folder Path:
Combine the folder path:

concat('/', outputs('Obj_Model')?['folderPath'], '/', outputs('Relative_URL'))

Get Files (SharePoint):
Use the SharePoint Get files (properties only) action with the dynamic path set to the DocumentPath variable.

Return Response:
Format the SharePoint file metadata (Name, Link, Type) and send it back using the Response action.

JavaScript (Executed on Page Load)

async function fetchSharePointFiles(recordId) {
  try {
    const response = await fetch("<YOUR_FLOW_HTTP_URL>", {
      method: "POST",
      headers: {
        "Content-Type": "application/json"
      },
      body: JSON.stringify({ recordId })
    });

    const data = await response.json();
    renderFiles(data);
  } catch (error) {
    console.error("Error retrieving files:", error);
  }
}

document.addEventListener("DOMContentLoaded", function() {
  const recordId = "{{yourRecordId}}"; // Replace dynamically or via Liquid
  fetchSharePointFiles(recordId);
});

Why This Works:

  • Fetches SharePoint files instantly on page load
  • Avoids dependency on unstable connectors
  • Offers better error handling and debugging visibility
  • Flexible to modify based on business needs

Pros:

  • Works reliably across all environments
  • No reliance on Power Pages native triggers
  • Cleaner control of request/response format

Cons:

  • Requires securing the HTTP endpoint
  • Slightly more manual setup

To conclude, if you’ve faced reliability issues with native Power Pages flow triggers, the HTTP request method can be a game-changer. It enabled me to deliver a seamless experience for retrieving SharePoint files, and it can do the same for your project.

In future iterations, I plan to enhance this by adding bearer token authentication and caching metadata for even faster performance.

Want to integrate Power Automate flows reliably with Power Pages? Reach out to CloudFronts—we help businesses implement scalable, reliable Power Platform solutions every day. You can contact us directly at transform@cloudfronts.com.


Share Story :

SEARCH BLOGS :

FOLLOW CLOUDFRONTS BLOG :


Secured By miniOrange