This declarative agent triggers a power automate flow as described in the blog post Build a Microsoft 365 Copilot Agent with Power Automate HTTP Trigger Using Agents Toolkit with OAuth 2 using TypeSpec.
This sample illustrates the following concepts:
- Building a declarative agent for Microsoft 365 Copilot using TypeSpec for Microsoft 365 Copilot
- Using the service 'https://service.flow.microsoft.com//.default' to invoke the Power Automate
- Using an automated approach to create the Entra ID app and the Developer Portal registration
- Reshmee Auckloo - M365 Development MVP
| Version | Date | Comments |
|---|---|---|
| 1.0 | May 05, 2026 | Initial solution |
- Microsoft 365 tenant with Microsoft 365 Copilot
- Visual Studio Code with the Microsoft 365 Agents Toolkit extension
- Node.js v20
- Clone this repository (or download this solution as a .ZIP file then unzip it)
- Open the Agents Toolkit extension and sign in to your Microsoft 365 tenant with Microsoft 365 Copilot
- Select Preview in Copilot (Edge) from the launch configuration dropdown
-
Set the request Body JSON Schema of the trigger action to:
{
"type": "object",
"properties": {
"body": {
"type": "string"
},
"email": {
"type": "string"
},
"subject": {
"type": "string"
}
}
}Add any actions like "Send an Email".
-
Set "Who can trigger the flow?" to "Any user in my tenant".
-
Copy the HTTP Url of the flow to use in the subsequent steps
- Go to Azure portal
- Select Microsoft Entra ID > Manage > App registrations > New registration
- Enter a name for the app (e.g., Volunteering App)
- Select Accounts in this organizational directory only
- Under Redirect URI, select Web and enter
https://teams.microsoft.com/api/platform/v1.0/oAuthRedirect - Select Register
- In the app registration, go to Certificates & secrets and create a new client secret
- Copy the client secret value
- In the app registration, go to API permissions and add the following permissions:
* Power Automate > Delegated permissions >
User - Select Grant admin consent for to grant the permissions

-
In the Teams Developer Portal, add a new OAuth client registration with the following details:
- Registration Name: InvokePAFlow
- Base URL: https://.09.environment.api.powerplatform.com
- Restrict Usage by Org: My organization only
-
OAuth Settings:
- Client ID:
<Entra ID Application ID> - Client Secret:
<Entra ID Application Secret> - Authorization Endpoint: https://login.microsoftonline.com/tenantid/oauth2/v2.0/authorize
- Token Endpoint: https://login.microsoftonline.com/tenantid/oauth2/v2.0/token
- Scope: https://service.flow.microsoft.com//.default (note the double slash before "default") otherwise you will encounter a forbidden error with a single slash.
- Client ID:
Replace tenantid with your tenant ID, which is a GUID.
Copy the value of the Oauth Client Registration ID.

- Open the file
.env.devwithin theenvfolder and update the following variables
PAAGENTAUTH_REGISTRATION_IDis the OAuth client registration ID you copied from step 3. Example:PAAGENTAUTH_REGISTRATION_ID=<oAuth Client Reg Id>PA_APP_SERVER_URLis the base URL of the Power Platform environment where your Power Automate flow is hosted. Example:PA_APP_SERVER_URL=https://<environmentname>.api.powerplatform.comPA_APP_INVOKE_PATHis the relative invoke path for the flow trigger, not the full URL. Use the path portion from the flow HTTP URL after the base Power Platform URL. Example:PA_APP_INVOKE_PATH=/powerautomate/automations/direct/workflows/.../triggers/manual/paths/invoke
We do not support samples, but this community is always willing to help, and we want to improve these samples. We use GitHub to track issues, which makes it easy for community members to volunteer their time and help resolve issues.
You can try looking at issues related to this sample to see if anybody else is having the same issues.
If you encounter any issues using this sample, create a new issue.
Finally, if you have an idea for improvement, make a suggestion.
THIS CODE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.

