# 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 {#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 {#list_runs}

```python
conn.list_runs(flow_id)
```

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`](https://zato.io/docs/dev/examples/cloud/power-automate/api/connection.html#invoke) for that page.

```python
# -*- 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}
```

```json
{"runs": [
  {"id": "08584623197582406521456132557CU12", "status": "Failed"},
  {"id": "08584623201955817033821090284CU07", "status": "Succeeded"}
]}
```

## get\_run {#get_run}

```python
conn.get_run(flow_id, run_id)
```

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.

```python
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 {#cancel_run}

```python
conn.cancel_run(flow_id, run_id)
```

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.

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

## resubmit\_run {#resubmit_run}

```python
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.

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

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

## See also {#see-also}

- [Monitoring Power Automate runs](https://zato.io/docs/dev/examples/cloud/power-automate/monitoring-runs.html) - The four run methods in complete services
- [Power Automate API - Flows](https://zato.io/docs/dev/examples/cloud/power-automate/api/flows.html) - trigger, which is what creates a run, and the other flow methods
- [Power Automate API - Connection](https://zato.io/docs/dev/examples/cloud/power-automate/api/connection.html) - invoke and get, for the next page of a long run history

## Learn more {#learn-more}

- [Development documentation](https://zato.io/docs/dev/) - Everything about writing services, in one place
- [Requests and responses](https://zato.io/docs/dev/request-response/) - What a service receives, what it returns and how to shape both
- [Integration examples](https://zato.io/docs/dev/examples/) - Ready-made code for the systems you are likely to connect to
- [IDE and debugging](https://zato.io/docs/dev/ide/) - Write services in the Dashboard or in your own editor
- [Data models](https://zato.io/docs/dev/model/) - Declare inputs and outputs and have them validated for you
- [In-depth API tutorial](https://zato.io/tutorials/main/01.html) - The full platform tutorial, from installation to production patterns
