Power Platform – Power Automate – How to verify status code return from the action – “Invoke an HTTP request”

Invoke HTTP request
Invoke HTTP request

Hi All,

Greetings for the day 🙂 LIFE IS BEAUTIFUL 🙂 I hope we all are safe 🙂 STAY SAFE, STAY HEALTHY 🙂 

Today might be small and common finding, but since it took me the time for again and required bit research so this article 🙂

Background : In one of my Power Automate I need to use “Invoke an HTTP request” action and based on the return status code I need to send an email either success or failure.

Invoke an HTTP Request action :

  • This action invokes an HTTP end point.
  • We need HTTP with Azure AD connector as
Power Platform - Power Automate - HTTP with Azure AD connector
Fig: Power Platform – Power Automate – HTTP with Azure AD connector
  • HTTP with Azure AD connector allows us get the resources from various web services using Azure Active Directory authentication
  • To use HTTP with Azure AD connector we will require Power Automate premium license
  • Invoke an HTTP Request action requires following parameters:
    • Method : One of the HTTP verb – POST, GET, DELETE, PUT, PATCH
    • URL of the request : Full relative URL of the resource. Ex. : To get all Groups we have Microsoft Graph REST API – https://graph.microsoft.com/v1.0/groups/
    • Body of the request : Body of the request / parameters if any

Example :

  • For demo purpose lets create a simple flow, we will trigger this flow manually
  • We will fetch all the groups using Microsoft Graph REST API – https://graph.microsoft.com/v1.0/groups/
  • From connector “HTTP with Azure AD“, add action “Invoke an HTTP request” as shown in below fig
Power Platform - Power Automate - HTTP with Azure AD connector - Adding "Invoke HTTP request" action to flow
Fig: Power Platform – Power Automate – HTTP with Azure AD connector – Adding “Invoke HTTP request” action to flow
Power Platform - Power Automate - Specifying details in "Invoke HTTP request" action
Fig: Power Platform – Power Automate – Specifying details in “Invoke HTTP request” action
  • We are ready to do first test run
  • We will test it manually
  • Click on “Test Flow” from right side pane and select option “Manually” as shown in below Fig
Power Platform - Power Automate - Testing the flow manually
Fig: Power Platform – Power Automate – Testing the flow manually
  • In the right side pane we will get the details like connection as shown in below Fig
Power Platform - Power Automate - Testing the flow manually - Run Flow
Fig: Power Platform – Power Automate – Testing the flow manually – Run Flow
Power Platform - Power Automate - Testing the flow manually - Run flow successfully
Fig: Power Platform – Power Automate – Testing the flow manually – Run flow successfully
  • Lets check the output of the action
  • In output we will get
    • statusCode – here 200 for success
    • headers details
    • body – having list of groups to which current account has the access
Power Platform - Power Automate - Output the flow
Fig: Power Platform – Power Automate – Output the flow
  • so till here all is OK 🙂
  • Now based on “statusCode” we need to send an email either success or failure
  • so we need to get the “statusCode” and we will store in a variable
  • Lets add new action “Initialize variable” as shown in below Fig
Power Platform - Power Automate - "Initialize variable" action
Fig: Power Platform – Power Automate – “Initialize variable” action
  • Here variable name is – “StatusCode” as shown in below Fig
  • We need to store the “statusCode” from the output of the action “Invoke HTTP request” in the “StatusCode” variable as shown in below Fig
Power Platform - Power Automate - storing "statusCode" from the output of action "Invoke HTTP request" to the variable "StatusCode"
Fig: Power Platform – Power Automate – storing “statusCode” from the output of action “Invoke HTTP request” to the variable “StatusCode”
  • We will use “outputs” expression to read the “statusCode” from the output of action “Invoke HTTP request” an in below code snippet
outputs('Get_all_Groups')?['statusCode']
  • Here, in “outputs” expression ‘Get_all_Groups’ is the action name which we renamed from “Invoke HTTP request” to “Get all Groups”
Power Platform - Power Automate - storing "statusCode" from the output of action "Invoke HTTP request" to the variable "StatusCode"
Fig: Power Platform – Power Automate – storing “statusCode” from the output of action “Invoke HTTP request” to the variable “StatusCode”
  • Once we have “statusCode” we are ready to check the condition and send email as shown in below Fig
Power Platform - Power Automate - verifying the condition for "statusCode"
Fig: Power Platform – Power Automate – verifying the condition for “statusCode”
  • So in this way based on the “statusCode” returned from “Invoke HTTP request” action we can execute the respective actions 🙂

I’ll stop here today 🙂

We have very good series on Power Automate – https://knowledge-junction.in/?s=power+automate OR https://knowledge-junction.in/?s=power+platform

We have very good series Microsoft Graph please have a look – https://knowledge-junction.in/?s=Microsoft+Graph

References:

Thanks for reading 🙂 If its worth at least reading once, kindly please like and share 🙂 SHARING IS CARING 🙂

Share In Teams:

Enjoy the beautiful life 🙂 Have a FUN 🙂 HAVE A SAFE LIFE 🙂 TAKE CARE 🙂

Prasham Sabadra

LIFE IS VERY BEAUTIFUL :) ENJOY THE WHOLE JOURNEY :) Founder of Knowledge Junction and live-beautiful-life.com, Author, Learner, Passionate Techie, avid reader. Certified Professional Workshop Facilitator / Public Speaker. Scrum Foundation Professional certificated. Motivational, Behavioral , Technical speaker. Speaks in various events including SharePoint Saturdays, Boot camps, Collages / Schools, local chapter. Can reach me for Microsoft 365, Azure, DevOps, SharePoint, Teams, Power Platform, JavaScript.

You may also like...

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: