Python Power Automate - Managing flows

Flows listed, inspected, enabled and disabled programmatically from Python services.

Beyond triggering flows, your services can manage them - list what exists in an environment, inspect individual flows, and turn them on or off. You create a Power Automate connection in the Dashboard and everything below is one call away.

Listing flows

conn.list_flows returns all the flows in the connection's environment. Each flow's details are nested under its properties key, following the Power Automate API's response shape.

# -*- coding: utf-8 -*-

# Zato
from zato.server.service import Service

class ListEnvironmentFlows(Service):

    def handle(self):

        # Get the connection by its Dashboard name
        conn = self.microsoft.power_platform['My Power Automate']

        # List all the flows in the environment
        response = conn.list_flows()

        # Extract the name and state of each one
        flows = []
        for flow in response['value']:
            flows.append({
                'id': flow['name'],
                'display_name': flow['properties']['displayName'],
                'state': flow['properties']['state'],
            })

        self.response.payload = {'flows': flows}

Inspecting a single flow

conn.get_flow returns full details of one flow, including its state, creation time and trigger information.

# -*- coding: utf-8 -*-

# Zato
from zato.server.service import Service

class GetFlowDetails(Service):

    input = 'flow_id'

    def handle(self):

        conn = self.microsoft.power_platform['My Power Automate']

        flow = conn.get_flow(self.request.input.flow_id)

        self.response.payload = {
            'display_name': flow['properties']['displayName'],
            'state': flow['properties']['state'],
            'created': flow['properties']['createdTime'],
        }

Enabling and disabling flows

conn.enable_flow and conn.disable_flow turn flows on and off - useful for maintenance windows, feature toggles, or reacting to incidents automatically.

# -*- coding: utf-8 -*-

# Zato
from zato.server.service import Service

class PauseNotificationsForMaintenance(Service):

    def handle(self):

        conn = self.microsoft.power_platform['My Power Automate']

        # Turn the notification flow off for the maintenance window ..
        conn.disable_flow('flow-customer-notifications')

        self.logger.info('Notifications paused for maintenance')
# -*- coding: utf-8 -*-

# Zato
from zato.server.service import Service

class ResumeNotificationsAfterMaintenance(Service):

    def handle(self):

        conn = self.microsoft.power_platform['My Power Automate']

        # .. and back on once the maintenance is over.
        conn.enable_flow('flow-customer-notifications')

        self.logger.info('Notifications resumed')

Anything else through the generic API

Every other flow management endpoint is reachable through conn.get, conn.post, conn.patch, conn.delete or conn.invoke - for instance, listing flows the connection's identity owns across environments.

# -*- coding: utf-8 -*-

# Zato
from zato.server.service import Service

class ListFlowsRaw(Service):

    def handle(self):

        conn = self.microsoft.power_platform['My Power Automate']

        # The same call that conn.list_flows makes, spelled out in full
        path = '/providers/Microsoft.ProcessSimple/environments/my-environment/flows'
        response = conn.get(path)

        self.response.payload = response

More resources

Learn more