Skip to content
Tutorials Center
My learning

Topics

Lesson 30 of 57 ยท Messaging and Integration

Logic Apps and API Management

Learn Azure Logic Apps workflows, triggers, actions and connectors, plus API Management gateways, policies, products and subscriptions.

Real systems rarely live in one place. An order arrives by web form, must be checked against a CRM, recorded in a database, announced in a chat channel, and exposed to partners through an API. Writing all that glue as custom code is slow and brittle. Azure offers two services that cover the glue, each from a different angle.

Azure Logic Apps is a workflow service: you describe "when this happens, do these steps" using ready-made connectors for hundreds of services, often with little or no code. Azure API Management (APIM) is a gateway that sits in front of your APIs and adds security, throttling, transformation and a developer portal, without changing the APIs themselves. Neither can run on this site, so the real definitions are read-only. The runnable stand-ins are Node.js programs that model a small workflow engine and an APIM-style rate-limit policy.

Logic Apps: workflows from triggers and actions

A workflow has exactly one trigger and one or more actions.

  • The trigger starts a run. It can be an incoming HTTP request, a schedule (recurrence), or an event such as "a row was added", "an email arrived" or "a message is in a queue". Triggers either push (a webhook calls the workflow) or poll (the service checks for new data on an interval).
  • Actions are the steps: call a connector operation, make an HTTP request, transform data, send a response, or control flow such as conditions, loops (for each) and parallel branches.
  • Connectors wrap services: Microsoft 365, Dataverse, Salesforce, SQL Server, Service Bus, Blob Storage, Slack and many more. A connection stores how to authenticate to a service. Where possible, use managed identities (see Managed Identities and Service Principals) rather than shared passwords.
  • Run history records each run and the inputs and outputs of every action, which is a great debugging tool.

There are two hosting models. Consumption is multitenant and billed per action execution, so it suits occasional workflows. Standard runs on a single-tenant runtime built on the Azure Functions host, hosts several workflows in one app, supports VNet integration and local development, and is billed by the hosting plan. Pricing and features evolve, so compare them on the pricing page when you decide.

Behind the designer, every workflow is a JSON definition. This simplified, read-only example receives an order over HTTP and answers according to its total:

JSON
{
  "triggers": {
    "When_an_order_arrives": {
      "type": "Request",
      "kind": "Http"
    }
  },
  "actions": {
    "Is_large_order": {
      "type": "If",
      "expression": { "greater": ["@triggerBody()?['total']", 500] },
      "actions": {
        "Respond_review": {
          "type": "Response",
          "kind": "Http",
          "inputs": { "statusCode": 202, "body": { "status": "needs review" } }
        }
      },
      "else": {
        "actions": {
          "Respond_ok": {
            "type": "Response",
            "kind": "Http",
            "inputs": { "statusCode": 200, "body": { "status": "approved" } }
          }
        }
      },
      "runAfter": {}
    }
  }
}

Expressions start with @ and call functions such as triggerBody(). Each action has a runAfter map saying which earlier actions must finish, and in what state (Succeeded, Failed, Skipped, TimedOut), before it runs. That is how you express error handling: an action that runs after another Failed is your "catch" block.

flowchart LR
    T["Trigger<br/>HTTP request"] --> A["Action: look up customer"]
    A -- "Succeeded" --> B["Action: save order"]
    A -- "Failed" --> E["Action: alert the team"]
    B --> R["Action: respond 200"]

Each action declares when it runs, depending on the result of the one before it.

Actions can have a retry policy (for example four attempts with exponential interval) for transient errors. Workflows should be idempotent, since a retry or a duplicated trigger can run an action twice.

A tiny workflow engine: a stand-in

The stand-in below runs a workflow like the one above. It is not the Logic Apps runtime: it only models the idea that actions run in dependency order, that each one has a runAfter condition, and that a failed step lets a "catch" step run while skipping the success path. The "look up customer" step is a fake that fails for one customer.

Node.js A workflow with runAfter

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Both runs show every action's final state, which is exactly what the Logic Apps run history displays for each run. Notice that on failure the success path is Skipped, not Failed.

When to choose Logic Apps

Logic Apps shines for integration and automation across SaaS services, approvals and scheduled jobs, where the connectors save weeks of work. It is a poorer fit for heavy computation, tight loops or logic that needs unit tests and code review; use Azure Functions for that, and call it from a workflow. Many solutions combine them: the workflow orchestrates, and functions do the custom work.

API Management: a front door for APIs

If you publish APIs to customers, partners or other teams, you quickly need the same extras for every API: authentication, rate limits, versioning, caching, logging, documentation, and a way to hand out keys. Building these into each backend duplicates work. API Management puts them in one place.

APIM has three parts:

  • The gateway receives API calls, applies policies and forwards them to the backend. It can be hosted by Azure, or self-hosted next to your backends.
  • The management plane (portal, CLI, ARM or Bicep, REST) is where you define APIs, products, policies and users.
  • The developer portal is a customizable website where consumers read documentation, try calls and obtain keys.

Tiers range from Developer (for non-production) through Basic, Standard and Premium (with multi-region and zone support) to newer v2 tiers and a Consumption tier priced per call; features and prices differ, so check the comparison before choosing.

APIs, products and subscriptions

  • An API is a set of operations imported from an OpenAPI definition, an Azure Function, a Logic App, an App Service or any HTTP backend.
  • A product bundles one or more APIs with terms of use, such as a "Free" product limited to 100 calls an hour and a "Gold" product with higher limits and approval required.
  • A subscription is a consumer's access to a product. It issues keys that the consumer sends in the Ocp-Apim-Subscription-Key header by default. Subscription keys identify and meter callers; they are not a strong authentication on their own, so combine them with OAuth for real security.
flowchart LR
    C["Client<br/>with subscription key"] --> G["APIM gateway"]
    G --> P1["Inbound policies<br/>auth, rate limit, transform"]
    P1 --> B["Backend API<br/>App Service or Function"]
    B --> P2["Outbound policies<br/>strip headers, cache"]
    P2 --> C

Policies run on the way in and on the way out; the backend stays unaware of most of the plumbing.

Policies

A policy is a small XML statement that changes how a request or response is handled. Policies are organized in four sections: inbound (before forwarding), backend, outbound (before returning to the client) and on-error, and can be set at several scopes (global, product, API, operation) that stack through <base />. Common policies:

Policy Purpose
rate-limit / rate-limit-by-key Allow at most N calls per time period; return 429 beyond that
quota A longer-term cap such as calls or bandwidth per month
validate-jwt Check an OAuth token's signature, issuer, audience and claims
set-header, set-query-parameter Add, change or remove headers and parameters
rewrite-uri, set-backend-service Change the path or the backend used
cache-lookup / cache-store Serve repeated reads from cache
mock-response Return a sample response before the backend exists
cors Handle cross-origin browser requests

A read-only policy that validates a token, limits each subscription to 5 calls a minute and hides a header on the way out (the tenant placeholder and claim are examples):

XML
<policies>
  <inbound>
    <base />
    <validate-jwt header-name="Authorization" failed-validation-httpcode="401"
                  failed-validation-error-message="Token missing or invalid">
      <openid-config url="https://login.microsoftonline.com/{tenant-id}/v2.0/.well-known/openid-configuration" />
      <audiences>
        <audience>api://orders-api</audience>
      </audiences>
    </validate-jwt>
    <rate-limit-by-key calls="5" renewal-period="60"
                       counter-key="@(context.Subscription.Id)" />
    <set-header name="X-Request-Source" exists-action="override">
      <value>apim</value>
    </set-header>
  </inbound>
  <backend>
    <base />
  </backend>
  <outbound>
    <base />
    <set-header name="X-Powered-By" exists-action="delete" />
  </outbound>
  <on-error>
    <base />
  </on-error>
</policies>

The token check relies on the tokens described in Microsoft Entra ID. Notice that none of this touches the backend: the same API can have different policies per product.

A rate-limit policy: a stand-in

The stand-in below models rate-limit-by-key with a fixed window keyed by subscription: each key may make 5 calls per 60-second window, then gets 429 with a Retry-After value until the window renews. The real policy has its own counting details; this models the behavior you observe as a client. Time is a fake clock.

Node.js Rate limit by subscription key

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

The counter is per key, so the free subscription is unaffected by the busy one. A well-behaved client reads Retry-After and waits instead of hammering the gateway.

Logic Apps and APIM together

The two services meet naturally: APIM can import a Logic App as an API, so a workflow with an HTTP trigger gets keys, throttling and a documented contract without the workflow knowing about any of it. Conversely, a workflow can call APIM-fronted APIs as just another HTTP action.

Common mistakes

  • Putting business logic only in a designer. Keep workflows readable; move complex code into functions and keep definitions in source control and Bicep (see Bicep and ARM Templates).
  • Polling triggers on a tight interval, which costs money for little benefit. Prefer push triggers when the source supports them.
  • Relying on subscription keys as the only security in APIM. Validate tokens too.
  • Forgetting that the backend is still reachable directly. Restrict backend access to the gateway (private networking or an allow list).
  • Setting no rate limits or quotas on a public API, which invites accidental and deliberate overload.

Power Platform, connectors and JSON in workflows

Logic Apps has a sibling for people who are not developers. The Microsoft Power Platform has four parts that work together:

  • Power Apps builds forms and apps (canvas apps for a free-form layout, model-driven apps over Dataverse data) with little or no code.
  • Power Automate builds flows: the same trigger-and-action idea as Logic Apps, with a friendlier designer, templates and per-user licensing.
  • Power BI builds reports and dashboards.
  • Copilot Studio builds conversational agents.

Power Automate and Logic Apps share the connector ecosystem, so a flow and a workflow can both talk to SharePoint, Outlook, SQL Server or your own API. The practical split: choose Power Automate for business-user automation tied to Microsoft 365, with licenses and governance managed by the Power Platform admins; choose Logic Apps for integrations owned by developers and IT, with source control, deployment pipelines, VNet integration and per-execution (Consumption) or plan-based (Standard) billing. When a Power App needs complex logic, it can call a Logic App through an HTTP trigger or call your API through APIM, which keeps the real logic reviewable.

HTTP triggers and custom connectors

An HTTP request trigger gives the workflow a callable URL with a signature in the query string (treat it as a secret: anyone with the URL can start the workflow, so restrict callers by IP or put API Management in front (see the section above)). You can describe the request body with a JSON schema so the designer offers the fields as named values. To reuse an API in many flows, wrap it as a custom connector from its OpenAPI definition; consumers then pick actions from a list instead of building raw HTTP calls. Connectors are versioned: Microsoft updates them and may deprecate old actions, so look at the version of an action in the designer and plan to update workflows when a connector announces a change.

Working with JSON

Most steps pass JSON around. Three tools cover nearly everything:

  • Parse JSON takes text and a schema and exposes its fields as dynamic content.
  • Expressions read and shape values: triggerBody()?['customer']?['email'] (the ? operators avoid errors on missing fields), body('Get_order'), items('For_each'), coalesce(a, b), json('{"a":1}'), concat(), formatDateTime().
  • Compose and Select build or reshape objects and arrays without code.

Always validate input before using it, return a clear error for bad data, and never assume a field exists. The stand-in below mimics Parse JSON with a schema check and optional chaining.

Schema-checked input: a stand-in

JS Parse JSON with a schema

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What does every Logic Apps workflow need to start a run?

    A workflow has one trigger that starts each run (HTTP request, schedule, or an event); actions then run according to their runAfter settings.
  2. 2. How do you build a 'catch' step that runs when a previous action fails?

    runAfter maps an earlier action to the states (Succeeded, Failed, Skipped, TimedOut) that allow the next action to run.
  3. 3. In API Management, what is a product?

    Products group APIs; subscriptions give consumers keys to a product, and policies can limit each product differently.
  4. 4. A client exceeds a rate-limit policy in APIM. What does it typically receive?

    The rate-limit policies answer 429 and include a Retry-After value.
  5. 5. Which is the better home for a CPU-heavy, unit-tested calculation in an integration solution?

    Use workflows for orchestration and connectors, and code (such as Functions) for custom logic you want to test and review.

Summary

  • Logic Apps workflows have one trigger and a graph of actions; connectors do the integration work, runAfter controls ordering and error handling, and run history shows what happened.
  • Consumption and Standard hosting differ in billing and capabilities; use code in Functions for heavy or testable logic.
  • API Management is a gateway with a management plane and a developer portal, putting security, throttling, transformation and documentation in front of any HTTP backend.
  • APIs are grouped into products; subscriptions issue keys; policies (inbound, backend, outbound, on-error) apply behavior such as validate-jwt, rate limits, header changes and caching.
  • Keys identify callers but do not replace token validation, and backends should only accept traffic from the gateway.

Next: Azure Container Registry.