← Back to Tutorials
Intermediate⏱️ 25 min

Calling REST APIs and Azure Functions from Logic Apps

Calling REST APIs and Azure Functions from Logic Apps

Logic Apps can call any REST API or Azure Function using the built-in HTTP action or dedicated connectors. This tutorial covers how to make HTTP requests, authenticate, parse responses, and handle errors.

HTTP Action

The HTTP action lets you call any REST endpoint with standard methods:

  • GET – Retrieve data from an API
  • POST – Send data to create a resource
  • PUT – Update an existing resource
  • DELETE – Remove a resource

Screenshot: Adding an HTTP action in the designer

To add an HTTP action:

  1. Click + New step in the designer
  2. Search for HTTP and select the built-in HTTP action
  3. Choose the method (GET, POST, PUT, DELETE)
  4. Enter the URI of the API endpoint

Setting Headers

Headers are configured in the HTTP action's Headers section. Common headers include:

HeaderPurpose
AuthorizationBearer token, API key, or Basic credentials
Content-Typeapplication/json, application/xml, etc.
AcceptExpected response format
Custom headersAny application-specific headers

Screenshot: Configuring headers in the HTTP action

Authentication Options

The HTTP action supports multiple authentication types:

TypeUse Case
NonePublic APIs with no auth
BasicUsername/password authentication
OAuth 2.0 (Active Directory)Azure AD-protected APIs
Managed IdentityAzure resources without storing credentials
API KeyAPIs that use key-based auth via header or query param

To configure authentication:

  1. Expand the Authentication dropdown in the HTTP action
  2. Select the authentication type
  3. Fill in the required fields (tenant ID, client ID, secret, etc.)

Screenshot: Authentication options dropdown

Parsing API Responses

After an HTTP call, use Parse JSON to work with the response body:

  1. Add a Parse JSON action after the HTTP step
  2. Set Content to the HTTP action's body output
  3. Provide a JSON schema (click Generate from sample to auto-generate)

Once parsed, individual fields are available as dynamic content in subsequent steps.

Screenshot: Parse JSON action with schema

Calling Azure Functions

You have two options for calling Azure Functions:

Built-in Azure Functions Connector

  • Automatically discovers functions in your subscription
  • Handles authentication via function keys
  • Provides a streamlined configuration experience

HTTP Action

  • More control over headers, authentication, and timeout
  • Required when using Managed Identity authentication
  • Works with functions in other subscriptions or tenants

Screenshot: Azure Functions connector vs HTTP action

Step-by-Step: Call a Public REST API

This example calls the JSONPlaceholder API to fetch a post and store the title in a variable.

1. Initialize a Variable

  1. Add Initialize variable action
  2. Name: PostTitle
  3. Type: String

2. Add HTTP GET Action

  1. Add an HTTP action
  2. Method: GET
  3. URI: https://jsonplaceholder.typicode.com/posts/1
  4. Headers: Accept: application/json

Screenshot: HTTP GET to JSONPlaceholder

3. Parse the Response

  1. Add Parse JSON action
  2. Content: @body('HTTP')
  3. Schema:
{
  "type": "object",
  "properties": {
    "userId": { "type": "integer" },
    "id": { "type": "integer" },
    "title": { "type": "string" },
    "body": { "type": "string" }
  }
}

4. Store in Variable

  1. Add Set variable action
  2. Name: PostTitle
  3. Value: Select title from Parse JSON dynamic content

Screenshot: Setting variable from parsed response

Step-by-Step: Call an Azure Function with Managed Identity

Prerequisites

  • A Logic App with a system-assigned or user-assigned Managed Identity enabled
  • An Azure Function with Azure AD authentication configured
  • The Logic App's identity granted access to the Function App

1. Enable Managed Identity on the Logic App

  1. Go to Logic App → IdentitySystem assigned → set Status to On
  2. Copy the Object ID for role assignment

2. Configure the Azure Function for AD Auth

  1. Go to Function App → AuthenticationAdd identity provider
  2. Select Microsoft and configure the App Registration

3. Grant Access

  1. Assign the Logic App's managed identity the appropriate role on the Function App (e.g., via Azure RBAC or the Function App's App Registration)

4. Add HTTP Action in Logic App

  1. Add an HTTP action
  2. Method: POST
  3. URI: https://your-function-app.azurewebsites.net/api/YourFunction
  4. Headers: Content-Type: application/json
  5. Body: your request payload
  6. Authentication:
    • Type: Managed Identity
    • Audience: https://your-function-app.azurewebsites.net

Screenshot: HTTP action with Managed Identity auth

Handling API Errors

Status Code Handling

Use Configure run after to branch logic based on success or failure:

  1. Add actions after the HTTP step
  2. Click ...Configure run after
  3. Select conditions: is successful, has failed, is skipped, has timed out

Common status codes to handle:

CodeMeaningAction
200/201SuccessContinue workflow
400Bad requestLog error, notify
401/403Auth failureRefresh token, retry
404Not foundHandle gracefully
429Rate limitedWait and retry
500+Server errorRetry with backoff

Retry Policy

Configure retries directly on the HTTP action:

  1. Click ...Settings on the HTTP action
  2. Under Retry Policy, choose:
    • Default – 4 retries with exponential backoff
    • Fixed interval – set count and interval
    • Exponential interval – set min/max interval and count
    • None – no retries

Screenshot: Retry policy configuration

Timeout Configuration

Set a timeout on the HTTP action to avoid long-running calls blocking your workflow:

  1. Click ...Settings on the HTTP action
  2. Set Timeout using ISO 8601 duration format (e.g., PT30S for 30 seconds, PT2M for 2 minutes)

The default timeout is 100 seconds. For long-running APIs, consider using the asynchronous polling pattern (the API returns 202 with a Location header).

Screenshot: Timeout configuration in action settings


PreviousNext
Error HandlingStateful vs Stateless