Python Power Automate - Triggering flows
Instant flows triggered by ID or callback URL, with payloads and synchronous responses.
Instant flows built around the "When an HTTP request is received" trigger are the most common way to run Power Automate from other systems. You create a Power Automate connection in the Dashboard, and your services trigger flows with a single call - Zato looks up the trigger's callback URL and sends the payload for you.
Triggering a flow by its ID
conn.trigger takes the flow's ID and the payload to send - it asks Power Automate for the flow's callback URL and posts the payload to it.
# -*- coding: utf-8 -*-
# Zato
from zato.server.service import Service
class SubmitInvoiceForApproval(Service):
input = 'invoice_id', 'amount'
def handle(self):
# Get the connection by its Dashboard name
conn = self.microsoft.power_platform['My Power Automate']
# Trigger the flow with the payload built from our input
result = conn.trigger('flow-invoice-approval', {
'invoice_id': self.request.input.invoice_id,
'amount': self.request.input.amount,
})
# If the flow responds synchronously, the result is its parsed JSON response
self.response.payload = {'status': 'submitted', 'result': result}
Triggering through a known callback URL
If you already have the trigger's callback URL - for instance, it was shared with you or you store it in configuration - use conn.trigger_url and skip the lookup. The URL includes its own authorization signature so no token is involved.
# -*- coding: utf-8 -*-
# Zato
from zato.server.service import Service
class NotifyOnNewCustomer(Service):
input = 'customer_id', 'customer_name'
def handle(self):
conn = self.microsoft.power_platform['My Power Automate']
# The callback URL, e.g. read from your configuration
url = 'https://prod-27.westeurope.logic.azure.com/workflows/abc123/triggers/manual/paths/invoke?sig=...'
conn.trigger_url(url, {
'customer_id': self.request.input.customer_id,
'customer_name': self.request.input.customer_name,
})
Looking up a trigger's callback URL
conn.get_trigger_url returns the callback URL itself, which is useful when you want to cache it or hand it over to another system.
# -*- coding: utf-8 -*-
# Zato
from zato.server.service import Service
class GetApprovalTriggerUrl(Service):
def handle(self):
conn = self.microsoft.power_platform['My Power Automate']
# Look up the callback URL of the flow's HTTP request trigger
url = conn.get_trigger_url('flow-invoice-approval')
self.response.payload = {'url': url}
Reading the flow's response
Flows that end with a "Response" action reply synchronously, and conn.trigger returns the parsed JSON of that reply. Flows without one return an empty acknowledgement, in which case the result is None.
# -*- coding: utf-8 -*-
# Zato
from zato.server.service import Service
class CheckDiscountEligibility(Service):
input = 'customer_id'
def handle(self):
conn = self.microsoft.power_platform['My Power Automate']
# This flow ends with a Response action, so we get its output back
result = conn.trigger('flow-discount-eligibility', {
'customer_id': self.request.input.customer_id,
})
self.response.payload = {'is_eligible': result['is_eligible']}