Power Automate API - Runs
list_runs, get_run, cancel_run and resubmit_run, with every parameter, and the run statuses.
A run is one execution of a flow, created each time one of the flow's triggers fires. Every run method takes the flow's ID, and all but list_runs take the run's ID too, which is the run's name in the listing.
Statuses
list_runs and get_run report one of these in properties.status:
| Status | Meaning |
|---|---|
Running | The flow is still executing, e.g. waiting for an approval or a delay |
Succeeded | Ended without error |
Failed | Ended with an error, details in properties.error |
Cancelled | Stopped with cancel_run or from Power Automate |
The first one means the run is still going, the other three mean it has ended.
list_runs
Returns the runs of a flow, newest first.
| Parameter | Type | Meaning |
|---|---|---|
flow_id | str | The flow's ID |
The result is a dict with the runs under value. Each run has its ID under name, and its properties hold status, startTime, endTime and, under trigger, the name of the trigger that started it and the times it fired. A flow with a long history returns its most recent runs and a nextLink with the URL of the next page - its path after the connection's address goes to conn.get for that page.
# -*- coding: utf-8 -*-
# Zato
from zato.server.service import Service
class ListRuns(Service):
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']:
runs.append({'id': run['name'], 'status': run['properties']['status']})
self.response.payload = {'runs': runs}
{"runs": [
{"id": "08584623197582406521456132557CU12", "status": "Failed"},
{"id": "08584623201955817033821090284CU07", "status": "Succeeded"}
]}
get_run
Returns one run.
| Parameter | Type | Meaning |
|---|---|---|
flow_id | str | The flow's ID |
run_id | str | The run's ID, its name in the listing |
The result is one element of the list_runs listing. For a run that failed, properties.error has a code and a message. A run ID the flow does not have raises an exception with the API's 404 response.
run = conn.get_run('8f3c1a2e-5b7d-4e9a-b6c0-2d4f7a9e1c35', '08584623197582406521456132557CU12')
run['properties']['status']
'Failed'
run['properties']['error']['message']
'Action Get_customer failed: the customer CUST-001 was not found'
cancel_run
Stops a run whose status is Running, so that its status becomes Cancelled.
| Parameter | Type | Meaning |
|---|---|---|
flow_id | str | The flow's ID |
run_id | str | The run's ID |
Returns nothing. Cancelling a run that has already ended raises an exception with the API's response.
resubmit_run
Runs the flow again with the same trigger input the given run had, as a new run.
| Parameter | Type | Meaning |
|---|---|---|
flow_id | str | The flow's ID |
run_id | str | The ID of the run to repeat |
trigger_name | str | The name of the trigger that started the run, manual by default, which is what Power Automate names an HTTP request trigger |
Returns nothing. The new run appears at the top of the list_runs listing, and the original stays there with its status unchanged. A run that is still going cannot be resubmitted and raises an exception with the API's response.
See also
| Page | What it covers |
|---|---|
| Monitoring Power Automate runs | The four run methods in complete services |
| Power Automate API - Flows | trigger, which is what creates a run, and the other flow methods |
| Power Automate API - Connection | invoke and get, for the next page of a long run history |