MSBA-273 · Lesson 9 of 12 · 19 min

Calling external APIs from flows

▶ Video coming soon A video version of this lesson is on the way.

Not every integration needs a developer's code. Many of Lumenvale's integrations were cloud flows built by makers in Facilities and the registrar's office, and several of them called systems outside Microsoft 365. The grounds supervisor at Ridgeview wanted a flow that read the next day's snowfall forecast from the weather service the college subscribed to and created snow-clearing work orders when the forecast passed a threshold. The Facilities purchasing coordinator wanted a flow that looked up a supplier's payment status in LedgerPoint, through the reporting connector Signe had built earlier, before approving a new purchase request. The ninth session looked at the ways a flow can call an external API, and at the governance, security and reliability questions each way raises.

Four ways to call out

A cloud flow can reach an external service in four main ways. The choice affects who can build and maintain the flow, how credentials are stored, how data policies treat it and what licence it needs.

Ways a cloud flow can call an external service.
WayWhat it isStrengthsWatch for
Prebuilt connectorA Microsoft or partner connector for the serviceTyped actions, managed authentication, documented limitsOnly exists for some services; some are premium
Custom connectorAn OpenAPI description of the service wrapped as a connectorReusable, typed actions; credentials in connections; governed in data policiesSomeone must build and maintain it
HTTP actionA raw HTTP request built in the flowQuick for one-off calls; any method and headerPremium; credentials easily end up in the flow; harder to govern
HTTP with Microsoft Entra IDA connector that sends requests to Entra-protected services with the user's sign-inNo secrets for services that accept Entra tokensOnly for services that trust Entra ID; preauthorized resources only

Signe's preference order was simple. Use a prebuilt connector if one exists and is supported. Otherwise build a custom connector if more than one flow or app will call the service, or if makers will maintain the flows. Use the raw HTTP action only for one-off calls owned by a developer, and only where data policies allow it. Several Microsoft 365 connectors also offer a generic send-an-HTTP-request action against their own service, such as SharePoint's, which is useful for operations the typed actions do not cover and stays within that connector's authentication.

A flow in the middle with four arrows to an external service: through a prebuilt connector, through a custom connector built from an OpenAPI definition, through a raw HTTP action, and through the HTTP with Microsoft Entra ID connector. A shield over the connectors represents data policies, which can allow or block each route.
Routes from a flow to an external API, all subject to data policies.

Custom connectors

A custom connector describes an API in OpenAPI format: its host, its operations, their parameters and responses, and its authentication. Once created, it appears to makers like any other connector, with typed actions and fields. Authentication options include no authentication, basic authentication, API key and OAuth 2.0, and the credentials live in each connection rather than in the flow. Custom connectors can be included in solutions, use policies to transform requests and responses, and, where needed, run a small C# script to reshape data. The earlier course Extending the Platform: Plug-ins, Custom APIs and Connectors covers building them; this lesson is about using them well in integrations.

The LedgerPoint reporting connector was a good example. LedgerPoint's reporting API used an API key. Signe's connector defined the key as a connection parameter, so the key was entered once when the shared connection was created and never appeared in any flow. In the solution, an environment variable held the API's base address for each environment, and a connection reference pointed flows to the right connection. The key itself was stored in Azure Key Vault, and a scheduled task in the CoE team's calendar reminded them to rotate it.

The HTTP action

The HTTP action sends any request to any address: method, URI, headers, query and body are all set in the flow. It is powerful and easy to misuse. A maker who pastes an API key into a header has put a secret in the flow definition, where anyone who can edit or export the flow can see it, and where run history may show it. If the HTTP action is unavoidable, the secret should come from an environment variable of the Secret type backed by Azure Key Vault, and the action's secure inputs and secure outputs settings should be turned on so that run history hides the values.

Listing 9.1: An HTTP action in a flow definition with the key from an environment variable, a retry policy and secure inputs and outputs (JSON, not executable here).
{
  "type": "Http",
  "inputs": {
    "method": "GET",
    "uri": "@{parameters('lcc_WeatherApiBaseUrl')}/forecast/daily",
    "queries": { "site": "ridgeview", "days": "2" },
    "headers": { "x-api-key": "@{parameters('lcc_WeatherApiKey')}" },
    "retryPolicy": { "type": "exponential", "count": 4, "interval": "PT10S" }
  },
  "runtimeConfiguration": {
    "secureData": { "properties": [ "inputs", "outputs" ] }
  }
}

In Listing 9.1 both the base address and the key come from environment variables, so nothing environment-specific or secret is in the flow itself. Wiremu pointed out that the grounds supervisor would not be able to maintain this action; if the weather service were to be used by several flows, a custom connector would be kept by IT and the supervisor would use its typed Get forecast action instead.

Data policies

Data loss prevention policies, which Microsoft now calls data policies in the admin centre, classify connectors into business, non-business and blocked groups and prevent a flow or app from combining business and non-business connectors. They apply to HTTP and custom connectors too. Administrators can block the HTTP action entirely in some environments, and for the HTTP connector and several others they can configure endpoint filtering, allowing only listed addresses. Custom connectors can be classified by URL pattern, so a policy can treat the college's own APIs as business and anything else as blocked.

Lumenvale's default environment blocked the HTTP action and all custom connectors. The Facilities production environment allowed the HTTP action only with endpoint filtering for the weather service's address, and classified the LedgerPoint reporting connector as business. Rupert reviewed every request to add an address to the filter. Makers occasionally found that frustrating; the alternative was a flow quietly sending staff data to an address nobody had reviewed.

Licensing

The HTTP action, the HTTP with Microsoft Entra ID connector and custom connectors are premium. A flow that uses them needs the maker and the flow to be covered by a premium Power Automate licence, such as a per-user premium licence, a per-flow licence for the flow, or a licence that includes premium use for flows in the context of a Power Apps or Dynamics 365 app. Rupert's team checked licensing as part of every integration review, because a flow built in a trial and moved to production without the right licence would stop running when the trial ended.

Making the call reliable

Every call to an external API can fail: the service is down, slow, throttling, or returns something unexpected. Flows provide the tools to handle that, and a production flow should use them.

Reliability tools for flows that call external APIs.
ToolUse
Retry policy on the actionRetries transient failures; set exponential or fixed intervals, or none for calls that must not repeat
Timeout settingLimits how long the action waits
Configure run afterRuns a step only when an earlier step failed, timed out or was skipped
Scopes as try and catchGroup the main steps in one scope and the error handling in another that runs after a failure
Parse JSON with a schemaTurns the response into typed fields and fails clearly if the shape changes
Terminate with a statusEnds a failed run as failed, so monitoring sees it

Retries need thought. Reading a forecast twice is harmless; creating a payment twice is not. A retry policy is safe only for idempotent calls, or for calls the external service can recognize as repeats, for example through an idempotency key sent in a header. For non-idempotent calls the flow should set the retry policy to none and handle failure explicitly.

Long-running external operations often use the asynchronous request pattern: the service responds 202 Accepted with a Location header, and the client polls that address until the work completes. The HTTP action follows that pattern automatically by default, which lets a flow wait for work that takes longer than a single request could. If the service does not implement the pattern correctly, the asynchronous behaviour can be turned off in the action's settings.

Worked problem

Counting calls in a loop

A first draft of the purchasing flow looped over each of the 40 lines on a purchase request and called the LedgerPoint connector once per line to check the supplier's status, although all lines had the same supplier. The flow runs about 30 times a working day. How many calls does the draft make per day, and how many if the supplier is checked once per request?

Show solution
  1. Draft: 40 calls per run times 30 runs is 1,200 calls a day.
  2. Revised: one call per run times 30 runs is 30 calls a day.
  3. The revised flow makes one fortieth as many calls, runs faster and is far less likely to meet the reporting API's rate limit.

Answer: 1,200 calls a day in the draft against 30 in the revision.

The example was based on a real draft from a maker, and Signe used it to make a general point. Calls inside loops multiply. A flow that calls an external API inside an apply-to-each loop should be checked for calls that could be moved outside the loop, combined into one request or cached in a variable.

Request limits on the flow side

Power Automate also has limits. Each licence comes with a daily allowance of Power Platform requests, every action counts as a request, and flows that exceed their allowance for a sustained period may be slowed. Connectors have their own throttling limits, documented on each connector's reference page. A flow that processes large volumes, such as thousands of rows a night, may be better as a dataflow or a pipeline, or as code calling bulk operations, as Lesson 7 described.

Inbound calls to flows

Flows can also be called from outside. The When an HTTP request is received trigger gives a flow an address that external systems can call. Microsoft has been changing how these triggers are secured and where their addresses are hosted, so Lumenvale's rule was to read the current documentation before using one, to restrict who can call the trigger with the options it offers, and never to treat the address as a secret that alone protects the flow. For most inbound integrations, Signe preferred a custom API or an Azure Function with proper authentication in front of Dataverse, as earlier lessons described.

Review checklist for an outbound flow

Questions Signe asked about every flow that called an external API.
QuestionGood answer
Is there a prebuilt or custom connector?Use it instead of the HTTP action
Where are credentials?In connections or Key Vault-backed secret environment variables, never in the flow
Is run history protected?Secure inputs and outputs on actions that carry sensitive data
Is the address allowed by data policies?Yes, classified or filtered by the CoE team
Are retries safe?Only for idempotent calls
Is failure visible?Errors handled in a catch scope that alerts the owner
Is it licensed?Premium coverage confirmed for the flow

Common mistakes

  • MistakePasting an API key into an HTTP action header.

    InsteadUse a custom connector connection or a Key Vault-backed secret environment variable, with secure inputs and outputs.

  • MistakeUsing the raw HTTP action for a service many flows call.

    InsteadBuild a custom connector that makers can use and IT can maintain.

  • MistakeLeaving the default retry policy on a call that creates something.

    InsteadTurn retries off for non-idempotent calls, or use an idempotency key.

  • MistakeCalling an external API once per item inside a loop when one call would do.

    InsteadMove the call outside the loop, combine requests or cache the result.

  • MistakeBuilding in a trial and assuming the flow will keep running.

    InsteadConfirm premium licensing before production.

  • MistakeTreating an HTTP trigger's address as its only protection.

    InsteadUse the trigger's caller restrictions or put an authenticated API in front.

Summary and key terms

  • Flows reach external APIs through prebuilt connectors, custom connectors, the HTTP action or the HTTP with Microsoft Entra ID connector.
  • Custom connectors keep credentials in connections, give makers typed actions and are governed by data policies.
  • The HTTP action is premium and easy to misuse; take secrets from Key Vault-backed environment variables and secure run history.
  • Data policies can block the HTTP action, filter its endpoints and classify custom connectors by URL pattern.
  • Retry policies, timeouts, run-after settings and try-and-catch scopes make calls reliable; retries suit only idempotent calls.
  • Calls inside loops multiply, and flows have their own request limits; large volumes belong in pipelines or bulk code.
Custom connector
A connector defined from an OpenAPI description of an API, with its own authentication, usable in flows and apps.
HTTP action
A premium flow action that sends an arbitrary HTTP request.
Endpoint filtering
A data policy setting that allows a connector such as HTTP to reach only listed addresses.
Secure inputs and outputs
Action settings that hide an action's inputs or outputs in flow run history.
Asynchronous request pattern
A pattern in which a service answers 202 Accepted with a status address that the client polls until the work completes.
Idempotency key
A unique value sent with a request so the service can recognize and ignore repeats.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. Why did Signe build a custom connector for LedgerPoint instead of letting makers use the HTTP action?

    Show answer

    Several flows needed it, makers could use typed actions, the API key stayed in the connection and data policies could govern it.

  2. What two settings stop an API key in an HTTP action from appearing in run history?

    Show answer

    Secure inputs and secure outputs.

  3. When should a flow action's retry policy be set to none?

    Show answer

    When the call is not idempotent, such as creating a payment, unless the service supports an idempotency key.

  4. What data policy feature limits the HTTP action to approved addresses?

    Show answer

    Endpoint filtering.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz