Skip to content
Tutorials Center
My learning

Topics

Lesson 20 of 38 ยท Connectors and Data

Calling REST APIs with the HTTP Action in Power Automate

Call any REST API from a flow with the HTTP action: methods, headers, bodies, authentication, Parse JSON, paging, retries and status codes, with runnable stand-ins.

When a service has no connector, or the connector lacks an operation, the HTTP action calls the API directly. It is a premium action, and it demands more care than a connector, because you handle authentication, paging and errors yourself.

Anatomy of the HTTP action

Field Meaning
Method GET, POST, PUT, PATCH, DELETE
URI The full address, including query string
Headers Content-Type, Accept, Authorization and others
Queries Key-value pairs added to the URI
Body The payload for POST, PUT and PATCH
Authentication None, Basic, Client certificate, Active Directory OAuth, Raw, Managed identity
Cookie Rarely used

Example POST with a JSON body:

TEXT
Method:  POST
URI:     https://api.example.com/v1/tickets
Headers: Content-Type: application/json
         Authorization: Bearer <token from a secure source>
Body:    {
           "title": "@{triggerBody()?['subject']}",
           "priority": "high"
         }

The action outputs the status code, headers and body. The body is raw text or JSON, so add Parse JSON (see Arrays, objects and JSON) to turn its fields into dynamic content, or read directly with body('HTTP')?['id'].

Authentication options

  • Raw header: you supply Authorization: Bearer .... Simple, but the token is visible in the flow unless it comes from Key Vault, and you must refresh it yourself.
  • Basic: username and password; use only over HTTPS and for low-risk APIs.
  • Active Directory OAuth: tenant, audience, client id and secret or certificate. Best for Entra-protected APIs. The platform fetches and refreshes the token for you.
  • Managed identity: for Azure resources from supported hosting.

Never paste long-lived secrets into the designer in plain text. Turn on Secure inputs for the action, and read secrets from Azure Key Vault or a secret environment variable.

Status codes decide what to do

By default the HTTP action marks the run Failed for status 400 and above (after retries for 408, 429 and 5xx). Often you want to read the error body. Change Configure run after on the next step so that it runs after a failure, then branch on outputs('HTTP')['statusCode'].

Code Meaning Common reaction
200, 201 OK or created Continue
204 No content Continue, no body
400 Bad request Fix input; do not retry
401, 403 Not authorized Refresh token or check permissions
404 Not found Handle as "does not exist"
429 Throttled Wait (use Retry-After) and retry
5xx Server error Retry with a delay

Retries and timeouts

In the action's Settings choose the Retry Policy: Default (four retries with exponential back-off), None, Fixed interval or Exponential interval. Retrying is safe for GET, but a POST that creates something can create duplicates if the first attempt actually succeeded. For such calls use an idempotency key header (if the API supports it) or set None and handle the error.

HTTP calls time out after about 2 minutes by default (the action's Timeout setting uses an ISO 8601 duration like PT1M). A long job should use the asynchronous pattern where the API returns 202 and a status URL that the flow polls (the HTTP action can do this automatically via Asynchronous pattern, on by default).

Paging through results

APIs return results in pages. Two common styles:

  • Next link: the body contains nextLink or next, a URL for the next page.
  • Page number or cursor: you pass page=2 or a cursor token.

Handle them with a Do until loop. Turn on the action's Pagination setting when the response uses a standard nextLink key.

Python Stand-in: follow a next link until there is none

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 input()), it gets the next line from this box.

Reacting to status codes

This stand-in decides what to do for each status code, as you would configure with run-after settings and a Condition.

Python Stand-in: retry or fail based on the status code

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 input()), it gets the next line from this box.

Building the body safely

JSON bodies built from text break when a value contains quotes or line breaks. Use json() and objects, or Compose with the JSON object typed as JSON, and let the platform quote the values:

TEXT
Compose  (Inputs)
{
  "title": @{outputs('Get_subject')},
  "notes": @{outputs('Get_notes')}
}

Here outputs('Get_subject') yields a string already quoted correctly in JSON context. Avoid wrapping tokens in extra quotes when they hold strings with special characters.

Python Stand-in: why text-built JSON breaks

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 input()), it gets the next line from this box.

Common mistakes

  • Putting a token or password directly in a header without secure inputs.
  • Forgetting Content-Type: application/json, so the API rejects the body.
  • Retrying POST calls blindly and creating duplicates.
  • Not checking statusCode and treating an error response as data.

You now have the main data tools of the course. The chapters that follow build on them: approvals and control flow come next in the track at Power Automate.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which header tells the API that the body is JSON?

    Content-Type declares the body format; JSON APIs expect application/json.
  2. 2. Why can retrying a POST be dangerous?

    If the first call worked but the response was lost, a retry may create a second record.
  3. 3. How do you read the status code of an action named HTTP?

    outputs('HTTP') exposes statusCode, headers and body.
  4. 4. What is the safest place to keep an API secret?

    Key Vault-backed storage keeps the secret out of the flow definition and run history.

Summary

  • The HTTP action calls any REST API; it is premium and leaves authentication, paging and errors to you.
  • Prefer Entra OAuth or Key Vault secrets over plain headers, and turn on secure inputs.
  • Check status codes, set retry policy carefully and handle paging with Do until or the pagination setting.
  • Build JSON from objects, not by gluing text.

Next: Approvals: Asking People to Decide