# Power Automate API - Flows

list\_flows, get\_flow, enable\_flow, disable\_flow, get\_trigger\_url, trigger and trigger\_url, with every parameter.

The flow methods work with the flows of the environment the connection points to. A flow is identified by its ID, the GUID at the end of its address in Power Automate, and every method except `trigger_url` takes that ID.

## Flow states {#flow-states}

`list_flows` and `get_flow` report one of these in `properties.state`:

| State | Meaning |
| --- | --- |
| `Started` | The flow is on, its triggers start runs |
| `Stopped` | The flow is off, its triggers do nothing |
| `Suspended` | Power Automate turned the flow off, e.g. after too many failures or for a licensing reason, and only a person can turn it back on |

## list\_flows {#list_flows}

```python
conn.list_flows()
```

Returns every flow in the environment.

The result is a dict with the flows under `value`. Each flow has its ID under `name`, and its `properties` hold `displayName`, `state`, `createdTime`, `lastModifiedTime` and the flow's `definitionSummary` with its triggers and actions.

```python
# -*- coding: utf-8 -*-

# Zato
from zato.server.service import Service

class ListFlows(Service):

    def handle(self):

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

        response = conn.list_flows()

        names = []
        for flow in response['value']:
            names.append(flow['properties']['displayName'])

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

```json
{"flows": ["Discount eligibility", "Order confirmation"]}
```

## get\_flow {#get_flow}

```python
conn.get_flow(flow_id)
```

Returns one flow.

| Parameter | Type | Meaning |
| --- | --- | --- |
| `flow_id` | str | The flow's ID |

The result is one element of the `list_flows` listing, with the full flow definition under `properties.definition` in addition to the summary. A flow ID the environment does not have raises an exception with the API's `404` response.

```python
flow = conn.get_flow('8f3c1a2e-5b7d-4e9a-b6c0-2d4f7a9e1c35')

flow['properties']['state']
'Started'
```

## enable\_flow {#enable_flow}

```python
conn.enable_flow(flow_id)
```

Turns a flow on, so that its state becomes `Started`.

| Parameter | Type | Meaning |
| --- | --- | --- |
| `flow_id` | str | The flow's ID |

Returns nothing. Enabling a flow that is already on changes nothing and raises nothing.

## disable\_flow {#disable_flow}

```python
conn.disable_flow(flow_id)
```

Turns a flow off, so that its state becomes `Stopped`. Runs that are already going carry on to their end, new ones do not start.

| Parameter | Type | Meaning |
| --- | --- | --- |
| `flow_id` | str | The flow's ID |

Returns nothing. Disabling a flow that is already off changes nothing and raises nothing.

## get\_trigger\_url {#get_trigger_url}

```python
conn.get_trigger_url(flow_id, trigger_name='manual')
```

Returns the callback URL of a flow's HTTP request trigger, the address a POST request goes to in order to start the flow.

| Parameter | Type | Meaning |
| --- | --- | --- |
| `flow_id` | str | The flow's ID |
| `trigger_name` | str | The name of the trigger in the flow's definition, `manual` by default, which is what Power Automate names an HTTP request trigger |

Returns the URL as a string. It includes a signature in its query string, so whoever has the URL can start the flow without a token. A flow without a trigger of that name raises an exception with the API's response.

```python
url = conn.get_trigger_url('8f3c1a2e-5b7d-4e9a-b6c0-2d4f7a9e1c35')

url
'https://prod-27.westeurope.logic.azure.com:443/workflows/6a2b.../triggers/manual/paths/invoke?api-version=2016-06-01&sp=...&sv=1.0&sig=...'
```

## trigger {#trigger}

```python
conn.trigger(flow_id, payload=None, trigger_name='manual')
```

Starts a flow by sending a payload to its HTTP request trigger. It calls `get_trigger_url` for the URL and then `trigger_url` with the payload, so each call makes two requests.

| Parameter | Type | Meaning |
| --- | --- | --- |
| `flow_id` | str | The flow's ID |
| `payload` | dict | The JSON body the trigger receives, or none |
| `trigger_name` | str | The name of the trigger, `manual` by default |

Returns the flow's response parsed from JSON when the flow replies with a body, and `None` when it replies with none. Whether a flow replies with a body, and when, is defined in the flow - a flow that replies at its end makes `trigger` wait until that end, a flow that replies as soon as it starts returns at once. A status code outside the success range raises an exception with the code and the response text.

```python
# -*- coding: utf-8 -*-

# Zato
from zato.server.service import Service

class CheckDiscount(Service):

    def handle(self):

        flow_id = '8f3c1a2e-5b7d-4e9a-b6c0-2d4f7a9e1c35'

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

        result = conn.trigger(flow_id, {'customer_id': 'CUST-001', 'order_total': 1250.50})

        self.response.payload = result
```

```json
{"customer_id": "CUST-001", "is_eligible": true, "discount_percent": 10}
```

## trigger\_url {#trigger_url}

```python
conn.trigger_url(url, payload=None)
```

Starts a flow by sending a payload straight to a callback URL, without looking it up first.

| Parameter | Type | Meaning |
| --- | --- | --- |
| `url` | str | A callback URL, as returned by `get_trigger_url` |
| `payload` | dict | The JSON body the trigger receives, or none |

Returns the same as `trigger`. The URL's signature is the only credential the request carries, the connection's token is not sent, so the call works with a URL of any flow in any environment, not only the connection's own.

```python
url = conn.get_trigger_url('8f3c1a2e-5b7d-4e9a-b6c0-2d4f7a9e1c35')

result = conn.trigger_url(url, {'customer_id': 'CUST-001', 'order_total': 1250.50})

result['discount_percent']
10
```

## See also {#see-also}

- [Triggering Power Automate flows](https://zato.io/docs/dev/examples/cloud/power-automate/triggering-flows.html) - trigger and trigger\_url in complete services
- [Managing Power Automate flows](https://zato.io/docs/dev/examples/cloud/power-automate/managing-flows.html) - list\_flows, get\_flow, enable\_flow and disable\_flow in complete services
- [Power Automate API - Runs](https://zato.io/docs/dev/examples/cloud/power-automate/api/runs.html) - The runs a trigger creates

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