Custom Triggers
Earn 25 points (50 with Pro) in two steps
- ① Read through the lesson — each section gets a ✓ as you scroll through it.
- ② When every section has a ✓, tap Complete lesson.
0 of 10 read · keep scrolling
✦ See fewer ads and earn double points — 50 a lesson instead of 25 — with Pro
Module: Integrate with Other Applications
Section: Power Platform Integration
Lesson Title: Custom Triggers
Introduction: The Power of Custom Triggers
In the ecosystem of the Microsoft Power Platform, automation is driven by events. Whether it is a new row added to a Dataverse table, an email arriving in an Outlook inbox, or a file being uploaded to SharePoint, these events serve as the starting point for Power Automate flows. However, standard connectors only take you so far. When you need to respond to specific events occurring in your own custom applications, legacy systems, or third-party web services that lack a native connector, you encounter a common limitation. This is where Custom Triggers become essential.
A custom trigger acts as the bridge between an external application and the Power Platform. By defining a custom trigger, you essentially tell Power Automate how to "listen" for a specific event in your external system. Instead of relying on a periodic check (polling), custom triggers allow your system to push data directly into a flow, making your automation more responsive, efficient, and reliable. Understanding how to build and manage these triggers is a critical skill for developers looking to create truly integrated, event-driven architectures.
This lesson explores the mechanics of custom triggers, the difference between polling and webhook triggers, the process of defining them in OpenAPI specifications, and the best practices for maintaining them in a production environment. By the end of this module, you will be able to design triggers that make your external applications feel like native citizens of the Power Platform.
Not read yet
The Core Concept: How Power Automate "Listens"
To understand custom triggers, we must first distinguish between the two primary ways a flow can start: Polling and Webhooks. These two patterns form the foundation of how Power Automate interacts with the outside world.
Polling Triggers
Polling is the process where Power Automate periodically asks your external service, "Has anything happened yet?" The flow engine runs on a schedule (e.g., every five minutes), calls your API endpoint, checks the response, and determines if a new event has occurred. If the event matches the criteria, the flow triggers.
- Pros: Easier to implement; does not require the external system to have knowledge of the Power Platform.
- Cons: Introduces latency; consumes API quota on your service; often results in "empty" requests if no data has changed.
Webhook Triggers
Webhooks are the "push" alternative. Instead of Power Automate checking for updates, your external system sends a notification to a specific URL provided by Power Automate as soon as an event occurs. This is significantly more efficient and provides near-instantaneous execution.
- Pros: Near-real-time performance; reduces unnecessary API calls; highly scalable.
- Cons: Requires your external system to manage the subscription lifecycle (registering and unregistering the URL); requires the external system to be accessible from the public internet.
Callout: Polling vs. Webhooks Choosing between polling and webhooks is a trade-off between simplicity and efficiency. Use polling when you have low volume or when your external API cannot support outgoing HTTP requests. Use webhooks for high-frequency events where latency is a concern and your API architecture allows for outbound callbacks.
Not read yet
Defining Custom Triggers in OpenAPI
Custom triggers are defined within a Custom Connector. A Custom Connector is essentially a wrapper around a REST API, and its structure is defined using the OpenAPI Specification (formerly known as Swagger). To create a custom trigger, you must add specific metadata to your OpenAPI file that tells Power Automate how to treat an endpoint as a trigger.
The Trigger Structure
When you define a trigger in the OpenAPI file, you must include the x-ms-trigger extension. This extension informs the Power Platform that this specific endpoint is not just a standard action, but a trigger that should appear in the "When a..." list within the flow designer.
Here is a simplified example of how this looks in JSON format:
"paths": {
"/on-new-order": {
"post": {
"summary": "When a new order is placed",
"description": "Triggers when a new order is received in the system.",
"x-ms-trigger": "single",
"responses": {
"200": {
"description": "OK"
}
}
}
}
}
In this snippet, x-ms-trigger: "single" indicates that this is a webhook-based trigger. When a user selects this trigger in a flow, Power Automate will perform a "subscribe" operation to register a callback URL with your service.
Not read yet
Step-by-Step: Building a Webhook Trigger
Implementing a webhook trigger involves two distinct phases: the subscription (registration) and the event notification (execution).
Step 1: Defining the Subscription
When a user adds your trigger to a flow, Power Automate sends an HTTP POST request to your API to register the webhook. Your API needs to capture this request, store the provided callback URL in your database, and return a successful response.
Step 2: The Callback Logic
When the event occurs in your application, your code must perform an HTTP POST to the callback URL provided during the subscription phase. The body of this POST request will be the data that the Power Automate flow receives as its trigger output.
Step 3: Handling Unsubscription
It is equally important to handle the unsubscription. If a user deletes the flow or disables it, Power Automate will send a DELETE request to your API. Your system must remove the callback URL from your database to prevent sending data to non-existent flows.
Warning: Security Considerations When exposing an endpoint for webhooks, ensure that you implement robust authentication. Power Automate includes a signature in the headers of its requests. You should verify this signature to ensure that the request is actually coming from the Power Platform and not a malicious actor trying to trigger your flows.
Not read yet
Practical Example: A Custom Inventory System
Imagine you manage an inventory system that tracks stock levels. You want a flow to trigger every time an item drops below a certain threshold.
The API Implementation
Your API should expose an endpoint /subscribe that accepts the callback URL and the threshold value.
// C# Example for a Subscription Endpoint
[HttpPost("subscribe")]
public IActionResult Subscribe([FromBody] SubscriptionRequest request)
{
// Save the callback URL and threshold to your database
_db.Subscriptions.Add(new WebhookSubscription {
CallbackUrl = request.CallbackUrl,
Threshold = request.Threshold
});
return Ok();
}
The Triggering Logic
When your inventory logic detects a change, it checks the database:
// Logic inside your inventory service
if (currentStock < subscription.Threshold)
{
var client = new HttpClient();
var content = new StringContent(JsonConvert.SerializeObject(new {
ItemName = item.Name,
StockLevel = currentStock
}), Encoding.UTF8, "application/json");
await client.PostAsync(subscription.CallbackUrl, content);
}
By following this pattern, your Power Automate flow remains completely decoupled from your inventory system's internal logic, while still reacting instantly to stock changes.
Not read yet
Polling Triggers: A Deeper Look
If your architecture cannot support webhooks, polling is the standard fallback. To implement a polling trigger, you need to define an endpoint that Power Automate can call repeatedly.
The x-ms-trigger: "polling" extension
Similar to webhooks, you use a specific extension in your OpenAPI file to define a polling trigger. Power Automate will expect the response from this endpoint to contain a list of items.
"paths": {
"/get-recent-orders": {
"get": {
"summary": "Get recent orders",
"x-ms-trigger": "polling",
"responses": {
"200": {
"description": "A list of orders"
}
}
}
}
}
Best Practices for Polling
- Use Delta Tokens: To avoid processing the same data repeatedly, design your API to accept a timestamp or a sequence ID. Only return records that have been created or modified after the provided value.
- Pagination: If your API returns large datasets, ensure your polling trigger supports pagination. Power Automate will automatically handle the "next link" if defined correctly.
- State Management: If you don't use delta tokens, your API must maintain state regarding what has already been sent to Power Automate. This can be complex and error-prone, so prioritize delta tokens whenever possible.
Not read yet
Best Practices and Industry Recommendations
Building custom triggers is a powerful capability, but it requires discipline to ensure stability and performance. Follow these industry-standard practices to keep your integrations clean.
- Keep Payloads Lightweight: Only send the data that the flow actually needs to perform its task. Sending massive JSON objects increases latency and consumes memory in the Power Automate execution engine.
- Error Handling: If your webhook notification fails, your API should implement a retry policy. However, do not retry indefinitely; implement an exponential backoff strategy to avoid overwhelming your own infrastructure.
- Version Control: Always version your API endpoints. When you make changes to the trigger schema, use a new version (e.g.,
/v2/on-new-order) to avoid breaking existing flows that rely on the original schema. - Documentation: Maintain clear documentation for your custom connector. Include details on the expected input parameters and the output schema so that other makers in your organization know how to use your triggers effectively.
- Monitoring: Implement logging for your subscription and notification endpoints. You need to know if a flow is failing to receive data because of a network issue or an invalid callback URL.
Callout: The Importance of Idempotency In distributed systems, retries are inevitable. Ensure your flow logic is idempotent—meaning that if the same trigger event is processed twice, it does not result in duplicate actions (like sending two emails or creating two records). Use a unique identifier from your external system to check for existing records before acting.
Not read yet
Common Pitfalls and How to Avoid Them
Even experienced developers can run into issues when implementing custom triggers. Here are the most frequent mistakes and how to steer clear of them.
1. Hardcoding URLs
Never hardcode the Power Automate callback URL in your application. The URL is dynamic and provided by the platform during the subscription request. Always store it in a database or a configuration cache associated with the specific flow instance.
2. Ignoring Timeout Limits
Power Automate expects a response from your service within a specific time window. If your webhook subscription logic performs heavy processing, the request might time out. Always offload heavy tasks to a background queue and return an immediate "202 Accepted" response to the Power Platform.
3. Lack of Security Validation
Do not assume that every request to your webhook endpoint is legitimate. As mentioned earlier, always validate that the request originated from the Power Platform by checking the authentication headers. Failure to do this leaves your system open to unauthorized triggers.
4. Over-triggering
If your logic is flawed, you might end up triggering the same flow thousands of times in a loop. Always implement circuit breakers or rate limiting in your API to protect your system from runaway automation.
Not read yet
Comparison Table: Trigger Types
| Feature | Polling Trigger | Webhook Trigger |
|---|---|---|
| Response Time | Delayed (based on interval) | Near-instant |
| Infrastructure | Simple (standard GET) | Complex (requires callback management) |
| Resource Usage | High (constant API calls) | Low (event-driven) |
| Complexity | Low | Moderate to High |
| Best Used For | Legacy systems, low-frequency data | Real-time integrations, high-frequency data |
Comprehensive Key Takeaways
To summarize the essential concepts of custom triggers in the Power Platform:
- Custom Triggers Extend Reach: They allow Power Automate to react to events in any system that exposes an API, moving beyond the limitations of built-in connectors.
- Choose the Right Pattern: Use polling for simple, low-frequency requirements and webhooks for high-performance, real-time event-driven architectures.
- Use OpenAPI Correctly: The
x-ms-triggerextension is the key to telling the Power Platform that your API endpoint should behave like a native trigger. - Manage the Lifecycle: Webhook triggers require your system to handle the registration, storage, and unsubscription of callback URLs.
- Prioritize Idempotency: Always design your flows to handle duplicate events gracefully, as network retries are a reality in cloud-based integrations.
- Security is Non-Negotiable: Always validate incoming requests to your webhook endpoints to ensure they are legitimate and authorized.
- Monitor and Version: Treat your custom connectors like software products. Implement logging, monitoring, and versioning to ensure your integrations remain stable as your systems evolve.
By mastering these concepts, you transition from being a passive user of the Power Platform to an active architect of your organization's digital ecosystem. The ability to create custom triggers unlocks a level of flexibility that allows your custom applications to participate fully in the automated workflows that power modern business processes.
Not read yet
FAQ: Frequently Asked Questions
Q: Can I use a custom trigger with an internal, on-premises system? A: Yes, but you must use the On-Premises Data Gateway. The gateway acts as a secure tunnel between your local network and the Power Platform, allowing the cloud to reach your internal API.
Q: How many flows can I trigger with a single custom trigger? A: There is no strict limit on the number of flows, but you should be mindful of the API rate limits of your external service. If you trigger too many flows simultaneously, you may hit your service's throughput limits.
Q: What happens if my webhook endpoint is down? A: If the Power Platform attempts to send a notification and receives an error, it will typically perform a series of retries. If the service remains down, the notification will eventually fail. Ensure your system has robust uptime to prevent data loss.
Q: Do I need a premium license to use Custom Connectors? A: Yes, Custom Connectors generally require a premium license for the user who owns or runs the flow. Always check the current Microsoft licensing documentation as these requirements can evolve.
Q: Can I pass complex JSON objects through a trigger? A: Absolutely. Power Automate is excellent at parsing JSON. As long as your OpenAPI definition accurately reflects the schema of the JSON you are sending, the flow will be able to map those fields to dynamic content.
Not read yet
Each section gets a ✓ as you scroll through it. Tap the button to jump to the next one.
No MB-220 practice exam yet
Your points already work on 76 Amazon, CompTIA and Microsoft exams.
See the exams