Triggering Power Automate flows

Trigger a flow by its ID or by its callback URL and read what the flow returns.

This page shows how to trigger a Power Automate flow from a Python service in two ways:

  1. By the flow's ID, with the connection looking up the callback URL
  2. By the callback URL itself, when the service already has it

A flow that a service triggers starts with an HTTP request trigger, and everything the flow does after that - approvals, Teams messages, SharePoint items, email - is defined in the flow and is not part of the service. The service sends a payload and receives whatever the flow replies with.

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.

Triggering a flow by its ID

In the tutorial, the payload was part of the service. In this example, a caller of the service sends the customer and the order total, and the service passes them to the flow.

The service below will:

  1. Take the customer ID and the order total from its input
  2. Trigger the flow with them, through conn.trigger
  3. Return the flow's response to the caller
# -*- coding: utf-8 -*-

# Zato
from zato.server.service import Service

class CheckDiscountForOrder(Service):

    name = 'power-automate.check-discount-for-order'
    input = 'customer_id', 'order_total'

    def handle(self):

        # The ID from the tutorial ..
        flow_id = '8f3c1a2e-5b7d-4e9a-b6c0-2d4f7a9e1c35'

        # .. the payload, taken from our input ..
        payload = {
            'customer_id': self.request.input.customer_id,
            'order_total': self.request.input.order_total,
        }

        # .. get a Power Automate connection ..
        conn = self.microsoft.power_platform['Zato Power Automate']

        # .. trigger the flow ..
        result = conn.trigger(flow_id, payload)

        # .. and return its response to our caller.
        self.response.payload = result

Invoked with {"customer_id": "CUST-001", "order_total": 1250.50}, the service returns:

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

conn.trigger returns the flow's response parsed from JSON. A flow that replies with no body makes it return None, and a service that only starts such a flow has nothing to read.

Triggering a flow by its callback URL

conn.trigger looks up the callback URL of the flow's trigger before each call. A service that already has the URL - read from its configuration, or received from another system - sends the payload to that URL with conn.trigger_url. The URL has its own signature built in, so the connection's token is not used.

# -*- coding: utf-8 -*-

# Zato
from zato.server.service import Service

class CheckDiscountByUrl(Service):

    name = 'power-automate.check-discount-by-url'
    input = 'customer_id', 'order_total'

    def handle(self):

        # The callback URL, as read from configuration ..
        url = self.config.power_automate.discount_flow_url

        # .. the payload, taken from our input ..
        payload = {
            'customer_id': self.request.input.customer_id,
            'order_total': self.request.input.order_total,
        }

        # .. get a Power Automate connection ..
        conn = self.microsoft.power_platform['Zato Power Automate']

        # .. send the payload to the URL ..
        result = conn.trigger_url(url, payload)

        # .. and return the flow's response to our caller.
        self.response.payload = result

The URL itself comes from conn.get_trigger_url, which is the lookup conn.trigger makes.

See also

PageWhat it covers
Power Automate API - Flowstrigger, trigger_url and get_trigger_url, with every parameter
Monitoring Power Automate runsThe run each trigger creates - reading, cancelling and resubmitting runs
Power Automate API - ConnectionThe connection form and how tokens are obtained and refreshed

Learn more