Power Automate API - Flows
list_flows, get_flow, enable_flow, disable_flow, get_trigger_url, trigger and trigger_url, with every parameter.
The flow methods work with the flows of the environment the connection points to. A flow is identified by its ID, the GUID at the end of its address in Power Automate, and every method except trigger_url takes that ID.
Flow states
list_flows and get_flow report one of these in properties.state:
| State | Meaning |
|---|---|
Started | The flow is on, its triggers start runs |
Stopped | The flow is off, its triggers do nothing |
Suspended | Power Automate turned the flow off, e.g. after too many failures or for a licensing reason, and only a person can turn it back on |
list_flows
Returns every flow in the environment.
The result is a dict with the flows under value. Each flow has its ID under name, and its properties hold displayName, state, createdTime, lastModifiedTime and the flow's definitionSummary with its triggers and actions.
# -*- coding: utf-8 -*-
# Zato
from zato.server.service import Service
class ListFlows(Service):
def handle(self):
conn = self.microsoft.power_platform['Zato Power Automate']
response = conn.list_flows()
names = []
for flow in response['value']:
names.append(flow['properties']['displayName'])
self.response.payload = {'flows': names}
get_flow
Returns one flow.
| Parameter | Type | Meaning |
|---|---|---|
flow_id | str | The flow's ID |
The result is one element of the list_flows listing, with the full flow definition under properties.definition in addition to the summary. A flow ID the environment does not have raises an exception with the API's 404 response.
enable_flow
Turns a flow on, so that its state becomes Started.
| Parameter | Type | Meaning |
|---|---|---|
flow_id | str | The flow's ID |
Returns nothing. Enabling a flow that is already on changes nothing and raises nothing.
disable_flow
Turns a flow off, so that its state becomes Stopped. Runs that are already going carry on to their end, new ones do not start.
| Parameter | Type | Meaning |
|---|---|---|
flow_id | str | The flow's ID |
Returns nothing. Disabling a flow that is already off changes nothing and raises nothing.
get_trigger_url
Returns the callback URL of a flow's HTTP request trigger, the address a POST request goes to in order to start the flow.
| Parameter | Type | Meaning |
|---|---|---|
flow_id | str | The flow's ID |
trigger_name | str | The name of the trigger in the flow's definition, manual by default, which is what Power Automate names an HTTP request trigger |
Returns the URL as a string. It includes a signature in its query string, so whoever has the URL can start the flow without a token. A flow without a trigger of that name raises an exception with the API's response.
url = conn.get_trigger_url('8f3c1a2e-5b7d-4e9a-b6c0-2d4f7a9e1c35')
url
'https://prod-27.westeurope.logic.azure.com:443/workflows/6a2b.../triggers/manual/paths/invoke?api-version=2016-06-01&sp=...&sv=1.0&sig=...'
trigger
Starts a flow by sending a payload to its HTTP request trigger. It calls get_trigger_url for the URL and then trigger_url with the payload, so each call makes two requests.
| Parameter | Type | Meaning |
|---|---|---|
flow_id | str | The flow's ID |
payload | dict | The JSON body the trigger receives, or none |
trigger_name | str | The name of the trigger, manual by default |
Returns the flow's response parsed from JSON when the flow replies with a body, and None when it replies with none. Whether a flow replies with a body, and when, is defined in the flow - a flow that replies at its end makes trigger wait until that end, a flow that replies as soon as it starts returns at once. A status code outside the success range raises an exception with the code and the response text.
# -*- coding: utf-8 -*-
# Zato
from zato.server.service import Service
class CheckDiscount(Service):
def handle(self):
flow_id = '8f3c1a2e-5b7d-4e9a-b6c0-2d4f7a9e1c35'
conn = self.microsoft.power_platform['Zato Power Automate']
result = conn.trigger(flow_id, {'customer_id': 'CUST-001', 'order_total': 1250.50})
self.response.payload = result
trigger_url
Starts a flow by sending a payload straight to a callback URL, without looking it up first.
| Parameter | Type | Meaning |
|---|---|---|
url | str | A callback URL, as returned by get_trigger_url |
payload | dict | The JSON body the trigger receives, or none |
Returns the same as trigger. The URL's signature is the only credential the request carries, the connection's token is not sent, so the call works with a URL of any flow in any environment, not only the connection's own.
url = conn.get_trigger_url('8f3c1a2e-5b7d-4e9a-b6c0-2d4f7a9e1c35')
result = conn.trigger_url(url, {'customer_id': 'CUST-001', 'order_total': 1250.50})
result['discount_percent']
10
See also
| Page | What it covers |
|---|---|
| Triggering Power Automate flows | trigger and trigger_url in complete services |
| Managing Power Automate flows | list_flows, get_flow, enable_flow and disable_flow in complete services |
| Power Automate API - Runs | The runs a trigger creates |