In this article, I walk you through how to add and trigger a Power Automate cloud flow from a Power Apps code app.
What type of flows can be added:
- Only Instant flows that use the Power Apps trigger are supported.
- You can’t add flows with other trigger types to a code app.
- These unsupported trigger types include scheduled, automated, or instant flows with non-Power Apps triggers.
- Flow must be solution-aware (i.e., must be part of a Dataverse solution)
Why Use Flows in Code Apps?
- Imagine you’re a developer building a custom app and you want to trigger a business process (like sending a notification or starting an approval) from your UI.
- You simply call existing Power Automate flow — and pass parameters to it.
Prerequisites
- A Power Platform environment
- Node.js installed
- VS Code
@microsoft/power-appsnpm package version 1.1.1 or later
Let’s start by configuring the cloud flow.
Create a Solution-Aware Instant Cloud Flow
- Created or open a solution. I created a new solution called DemoCodeAppFlow.
- Add a new instant cloud flow by navigating to the solution > New > Automation > Cloud flow > Instant

- Provide a flow name, example, Instant-flow-triggered-by-code-app and select the “When Power Apps calls a flow (V2)” trigger.

- Add a text input parameter called msgFromCodeApp to the trigger. This is what the code app will pass to the flow as a parameter.

- I wanted the flow to be simple, hence I only added a Compose action that reads and used the
msgFromCodeAppparameter as dynamic content. This is just to verify the value received from the code app.

- Save and Publish the flow.
Now that the cloud flow is configured and ready to be called from the Code App, let’s capture the Environment ID before we move on to building the Code App.
Copy the Environment ID:
- Open the Settings > Session details in Power Apps and copied the Environment ID.

Let’s proceed with the Code App project configuration.
Create the Code App Project:
- Open the VS Code > Terminal
- Run the following command to scaffold a new code app from the Vite template:
npx degit github:microsoft/PowerAppsCodeApps/templates/vite demo-codeapp-flow

- Install Dependencies by running following command:
cd demo-codeapp-flownpm install

- Next, Initialize the code app with environment id (Copied in above steps) and display name:
npx power-apps init --display-name "Demo-CodeApp-Flow" --environment-id ebb51434-39ed-e71a-8aa0-42033d9afb13
Now we have the ‘Code App’ project created and initialized. Next we will be adding the cloud flow.
Add Cloud Flow to Code App:
- Run following command to list all available flows in the environment to find our flow ID. Copy the Flow ID for Instant-flow-triggered-by-code-app.
npx power-apps list-flows

- Run the
add-flowcommand with the copied flow ID:
npx power-apps add-flow --flow-id 5d7d5ed8-584b-8b27-c0fe-adf10c84ee27
- This generate a strongly-typed TypeScript files under
src/generated/:- models/ —
ManualTriggerInputinterface with thetextparameter - services/ —
Instant_flow_triggered_by_code_appServiceclass with aRun()method
- models/ —

- Next update the
App.tsxby adding a simple form that takes a message as parameter and triggers the flow. The key line is:
const result = await Instant_flow_triggered_by_code_appService.Run({ text: message })

- The full source code is available on GitHub: demo-codeapp-flow
- Use npm run dev to run the app locally and test the UI.
npm run dev

- Once you are happy with the UI, run
pac code pushto publish the code app to the Power Platform environment:

- Once the app is published to the Power Platform environment, open and play the app.
- Test it by typing a message — for example, “Hello from code app” — and clicking Run Flow. The flow should trigger successfully.

- Check the flow run history in Power Automate to confirm the flow was triggered successfully.

Hope you have learned how to:
- Create a solution-aware instant cloud flow with a Power Apps trigger
- Scaffold a Power Apps code app using the Vite template
- Add the flow to the code app using
npx power-apps add-flow - Write React/TypeScript code to call the flow and pass parameters
- Test the app and verify the flow run
📖 Official documentation: Add Power Automate flows to a code app
💻 Source code: GitHub – demo-codeapp-flow
🙂



Leave a comment