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:

StatusMeaning
RunningThe flow is still executing, e.g. waiting for an approval or a delay
SucceededEnded without error
FailedEnded with an error, details in properties.error
CancelledStopped 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

conn.list_runs(flow_id)

Returns the runs of a flow, newest first.

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

conn.get_run(flow_id, run_id)

Returns one run.

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

conn.cancel_run(flow_id, run_id)

Stops a run whose status is Running, so that its status becomes Cancelled.

ParameterTypeMeaning
flow_idstrThe flow's ID
run_idstrThe run's ID

Returns nothing. Cancelling a run that has already ended raises an exception with the API's response.

conn.cancel_run('8f3c1a2e-5b7d-4e9a-b6c0-2d4f7a9e1c35', '08584623197582406521456132557CU12')

resubmit_run

conn.resubmit_run(flow_id, run_id, trigger_name='manual')

Runs the flow again with the same trigger input the given run had, as a new run.

ParameterTypeMeaning
flow_idstrThe flow's ID
run_idstrThe ID of the run to repeat
trigger_namestrThe 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.

conn.resubmit_run('8f3c1a2e-5b7d-4e9a-b6c0-2d4f7a9e1c35', '08584623197582406521456132557CU12')

See also

PageWhat it covers
Monitoring Power Automate runsThe four run methods in complete services
Power Automate API - Flowstrigger, which is what creates a run, and the other flow methods
Power Automate API - Connectioninvoke and get, for the next page of a long run history

Learn more