Monitoring Power Automate runs
Read a flow's run history, read one run, cancel a run that is still going and resubmit one that failed.
Each time a flow is triggered, Power Automate records a run. This page shows how a Python service works with the runs of a flow:
- Reading the run history and picking out the runs of one status
- Reading one run
- Cancelling a run that is still going
- Resubmitting a run that failed
Connection and IDs
The app registration, the Power Automate connection in the Zato Dashboard and the flow ID are the same as in the tutorial, so set them up as described there first.
Reading the run history
conn.list_runs returns the runs of a flow, newest first. The runs are under value, each run's ID is its name, and its status and times are under properties. The service below takes a status from its input and returns the runs that have it.
# -*- coding: utf-8 -*-
# Zato
from zato.server.service import Service
class ListRunsByStatus(Service):
name = 'power-automate.list-runs-by-status'
input = 'status'
def handle(self):
flow_id = '8f3c1a2e-5b7d-4e9a-b6c0-2d4f7a9e1c35'
conn = self.microsoft.power_platform['Zato Power Automate']
response = conn.list_runs(flow_id)
runs = []
for run in response['value']:
if run['properties']['status'] == self.request.input.status:
runs.append({
'id': run['name'],
'started': run['properties']['startTime'],
})
self.response.payload = {'runs': runs}
Invoked with {"status": "Failed"}, the service returns:
{"runs": [
{"id": "08584623197582406521456132557CU12", "started": "2026-09-27T14:03:19.7140252Z"}
]}
Reading one run
conn.get_run returns one run with its status, its start and end times and, for a run that failed, the error under properties.error.
# -*- coding: utf-8 -*-
# Zato
from zato.server.service import Service
class GetRun(Service):
name = 'power-automate.get-run'
input = 'run_id'
def handle(self):
flow_id = '8f3c1a2e-5b7d-4e9a-b6c0-2d4f7a9e1c35'
conn = self.microsoft.power_platform['Zato Power Automate']
run = conn.get_run(flow_id, self.request.input.run_id)
self.response.payload = {
'status': run['properties']['status'],
'started': run['properties']['startTime'],
'ended': run['properties']['endTime'],
}
{"status": "Failed", "started": "2026-09-27T14:03:19.7140252Z", "ended": "2026-09-27T14:03:21.0021873Z"}
Cancelling a run
conn.cancel_run stops a run whose status is Running, and returns nothing.
# -*- coding: utf-8 -*-
# Zato
from zato.server.service import Service
class CancelRun(Service):
name = 'power-automate.cancel-run'
input = 'run_id'
def handle(self):
flow_id = '8f3c1a2e-5b7d-4e9a-b6c0-2d4f7a9e1c35'
conn = self.microsoft.power_platform['Zato Power Automate']
conn.cancel_run(flow_id, self.request.input.run_id)
self.response.payload = {'run_id': self.request.input.run_id, 'status': 'Cancelled'}
Resubmitting a failed run
conn.resubmit_run runs the flow again with the same trigger input the original run had, and returns nothing. The service below combines it with the filter from the first example, resubmitting every run that failed.
# -*- coding: utf-8 -*-
# Zato
from zato.server.service import Service
class ResubmitFailedRuns(Service):
name = 'power-automate.resubmit-failed-runs'
def handle(self):
flow_id = '8f3c1a2e-5b7d-4e9a-b6c0-2d4f7a9e1c35'
conn = self.microsoft.power_platform['Zato Power Automate']
response = conn.list_runs(flow_id)
resubmitted = []
for run in response['value']:
if run['properties']['status'] == 'Failed':
conn.resubmit_run(flow_id, run['name'])
resubmitted.append(run['name'])
self.response.payload = {'resubmitted': resubmitted}
Each resubmission is a new run in the history, the failed one stays there with its status unchanged.
See also
| Page | What it covers |
|---|---|
| Power Automate API - Runs | list_runs, get_run, cancel_run and resubmit_run, with every parameter and the run statuses |
| Triggering Power Automate flows | Triggering a flow to create a run |
| Managing Power Automate flows | Listing flows and turning them on and off |