Skip to content

Add cloud-flow sample (React)#102

Merged
tyaginidhi merged 7 commits into
mainfrom
sample/cloud-flow
Jun 25, 2026
Merged

Add cloud-flow sample (React)#102
tyaginidhi merged 7 commits into
mainfrom
sample/cloud-flow

Conversation

@tyaginidhi

@tyaginidhi tyaginidhi commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

What

Adds a small, single-topic sample that shows how to invoke a Power Automate cloud flow from a Power Pages code site — the smallest app that proves the concept (one form, one button, one flow call), in React.

The whole lesson lives in one file (cloudFlowClient.ts); the rest is just UI to trigger the call and render the three states (loading, error, result).

What it teaches

  • Calling a registered cloud flow with POST /_api/cloudflow/v1.0/trigger/<flowId>
  • Sending the required __RequestVerificationToken (CSRF) and X-Requested-With: XMLHttpRequest headers — the endpoint only accepts AJAX requests; omitting the latter fails with a masked 500
  • Matching request body keys to the flow trigger's input parameters, and reading the JSON returned by a Respond to Power Pages action (whose property names come back lowercased)

Low-friction setup

The sample ships everything needed to stand it up with import → build → upload:

  • Bundled flow as an importable unmanaged solution (flow/CloudFlowSample_1_0_0_0.zip) — import it instead of hand-authoring the trigger/respond actions. An unmanaged import preserves the flow GUID, so FLOW_ID in config.ts is pre-filled and needs no edit.
  • Registration as code.powerpages-site/cloud-flow-consumer/*.cloudflowconsumer.yml registers the flow to the site and grants the Authenticated Users web role automatically on pac pages upload-code-site, removing the manual Set up → Cloud flows → Add cloud flow studio step.
  • README follows the established environment-variables-samples style: what it teaches, Option A (import) / Option B (author your own, with an exact case-sensitive input/output checklist), an Authorization section (web roles bind to contacts) and a Troubleshooting section (the X-Requested-With 500, the lowercased response keys, flow run history).
  • Build uses content-hashed bundle filenames so re-uploading after a FLOW_ID change never serves a stale cached bundle.

Index rows added to the root README.md and samples/spa/README.md.

Verification

  • npm run build clean.
  • Verified end-to-end against a live Power Pages site: submitting the form invokes the flow and renders the returned ticket / message / estimated callback (HTTP 200).
  • Confirmed pac pages upload-code-site deploys the bundled cloud-flow-consumer registration (creates the adx_cloudflowconsumer record bound to the flow + Authenticated Users role).

🤖 Generated with Claude Code

tyaginidhi and others added 4 commits June 23, 2026 15:16
Invoke a registered Power Automate cloud flow from a code site via
POST /_api/cloudflow/v1.0/trigger/<FLOW_ID> with the CSRF token, and
render the response. React is the canonical reference; Angular and Vue
are faithful ports of the identical scenario. Ships .powerpages-site
metadata per variant and index rows in the root and SPA READMEs.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Apply learnings from end-to-end setup so makers hit fewer manual steps:

- Ship the flow as an importable unmanaged solution
  (flow/CloudFlowSample_1_0_0_0.zip) in each variant. README "Set up the
  flow" now offers Option A (import the solution — fastest) and Option B
  (author it yourself, with an exact case-sensitive input/output checklist
  and a "names must match the client" warning).
- Pre-fill FLOW_ID in config.ts with the bundled flow's GUID. An unmanaged
  import preserves the GUID, so the import path needs no edit; the comment
  explains both paths.
- Add "Authorization (who can call the flow)" and "Troubleshooting"
  sections: web roles bind to contacts, the 500 is usually an auth/role
  issue, and the flow's run history distinguishes a portal-side problem
  (0 runs) from flow logic (failed run).
- React: emit content-hashed bundle filenames (index-[hash].js) and match
  bundleFilePatterns, so re-uploading after changing FLOW_ID never serves a
  stale cached bundle.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…sing

Verified end-to-end against a live Power Pages site (form submit ->
flow run -> rendered response). Two correctness fixes:

- Send the X-Requested-With: XMLHttpRequest header on the trigger call.
  The cloud flow endpoint only accepts AJAX requests; without this header
  it rejects the call with a masked HTTP 500 ("view 'Error' not found in
  /Areas/PowerAutomate/...") and the flow never runs. CSRF alone is not
  enough. Confirmed: same request with the header returns 200, without it
  returns 500.
- Map the response keys defensively. Power Pages lowercases the Respond
  action's output property names on the wire (ticketNumber -> ticketnumber),
  so the typed response is rebuilt from the lowercased keys.

READMEs updated: Key points lists both required headers; Troubleshooting
leads with the X-Requested-With cause and documents the lowercased response
keys.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add .powerpages-site/cloud-flow-consumer/*.cloudflowconsumer.yml to each
variant so `pac pages upload-code-site` registers the flow to the site and
grants the Authenticated Users web role automatically — removing the manual
"Set up > Cloud flows > Add cloud flow" studio step from Option A.

Verified by re-uploading the React site: pac created the adx_cloudflowconsumer
record (a powerpagecomponent type 33) from the YAML, with processid pointing at
the bundled solution's flow GUID and the Authenticated Users role bound. The
role id (d60cc079...) matches the Authenticated-Users.webrole.yml the sample
already ships, so the reference resolves on a fresh deploy. Each variant uses a
distinct consumer id to avoid collisions if deployed into the same environment.

README Option A updated: import solution -> build -> upload, fully wired.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Capture the sample UI (form + rendered flow response) and add it as
screenshot.png to each variant, fixing the broken image references in the
root and SPA index tables and the per-variant READMEs. Add the matching
Screenshot section to the Angular and Vue READMEs for parity with React.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot stopped reviewing on behalf of tyaginidhi due to an error June 24, 2026 17:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

tyaginidhi and others added 2 commits June 24, 2026 23:17
Replace the per-field ?? fallbacks with a single case-insensitive helper so
all three response fields (including message) are read uniformly, rather than
mapping ticketNumber/estimatedCallback defensively while reading message
directly. Power Pages lowercases the Respond action's output property names on
the wire, so the helper tries the exact key then its lowercase form.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Remove the Angular and Vue cloud-flow-sample variants and their
README references, leaving the React + Vite sample as the single
cloud-flow recipe.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@tyaginidhi tyaginidhi enabled auto-merge (squash) June 25, 2026 07:52
@tyaginidhi tyaginidhi changed the title Add cloud-flow sample (React, Angular, Vue) Add cloud-flow sample (React) Jun 25, 2026
@tyaginidhi tyaginidhi merged commit 0599b06 into main Jun 25, 2026
3 checks passed
@tyaginidhi tyaginidhi deleted the sample/cloud-flow branch June 25, 2026 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants