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:

StateMeaning
StartedThe flow is on, its triggers start runs
StoppedThe flow is off, its triggers do nothing
SuspendedPower 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

conn.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}
{"flows": ["Discount eligibility", "Order confirmation"]}

get_flow

conn.get_flow(flow_id)

Returns one flow.

ParameterTypeMeaning
flow_idstrThe 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.

flow = conn.get_flow('8f3c1a2e-5b7d-4e9a-b6c0-2d4f7a9e1c35')

flow['properties']['state']
'Started'

enable_flow

conn.enable_flow(flow_id)

Turns a flow on, so that its state becomes Started.

ParameterTypeMeaning
flow_idstrThe flow's ID

Returns nothing. Enabling a flow that is already on changes nothing and raises nothing.

disable_flow

conn.disable_flow(flow_id)

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.

ParameterTypeMeaning
flow_idstrThe flow's ID

Returns nothing. Disabling a flow that is already off changes nothing and raises nothing.

get_trigger_url

conn.get_trigger_url(flow_id, trigger_name='manual')

Returns the callback URL of a flow's HTTP request trigger, the address a POST request goes to in order to start the flow.

ParameterTypeMeaning
flow_idstrThe flow's ID
trigger_namestrThe 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

conn.trigger(flow_id, payload=None, trigger_name='manual')

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.

ParameterTypeMeaning
flow_idstrThe flow's ID
payloaddictThe JSON body the trigger receives, or none
trigger_namestrThe 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
{"customer_id": "CUST-001", "is_eligible": true, "discount_percent": 10}

trigger_url

conn.trigger_url(url, payload=None)

Starts a flow by sending a payload straight to a callback URL, without looking it up first.

ParameterTypeMeaning
urlstrA callback URL, as returned by get_trigger_url
payloaddictThe 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

PageWhat it covers
Triggering Power Automate flowstrigger and trigger_url in complete services
Managing Power Automate flowslist_flows, get_flow, enable_flow and disable_flow in complete services
Power Automate API - RunsThe runs a trigger creates

Learn more