Skip to main content

Notifications

Power Automate - Building Flows
Unanswered

Flow trigger "When a HTTP request is received" and "Any user in my tenant"

Posted on by 2
I have a flow with the "When a HTTP Request is received" trigger and want to use the "Any user in my tenant" option, so that it cannot be called anonymously.
 
I have created the necessary App Registration in Azure, created a client secret, and  given the app registration the correct permission to use Power Automate.
 
Does anyone have an example of how to build the some client-side JavaScript code to call the Flow, passing in the necessary OAuth authentication values? I have seen plenty of examples using Postman, but no examples of any JavaScript making the call.
 
Example using Postman
 
This announcement and the documentation don't show you how to do it from Javascript calling code, on the client
 
 
Thank you in advance
Categories:
  • Pete_L Profile Picture
    Pete_L 2 on at
    Flow trigger "When a HTTP request is received" and "Any user in my tenant"
    I worked this out, so I am answering my own question, in case it helps others:
     
    First, in JavaScript, you have to make a call to get a Bearer token. Then add the value of that token to the headers of the JavaScript request to the Flow. The "code" option in Postman helps to generate the necessary JavaScript (or many other languages) to make the call. The redacted code is below - I have redacted the full body of the very long token and the URL of my Flow, and I have used an example URL variable name, to show a parameter being passed into the Flow.
     
    In reality, you would not hard code the token, you would make a JavaScript call to get it. You would supply these values to get the token:
    • GET: https://login.microsoftonline.com/[TenantID]/oauth2/v2.0/token
    • grant_type: client_credentials
    • client_id: your clinet (application) id from Azure
    • client_secret: the secret, from Azure
    • scope: https://service.flow.microsoft.com//.default
    • See video in main post for how to do this
    const myHeaders = new Headers();
    
    //Then use the value of the token in the "append" method, to the headers
    //Note there is a space between the word Bearer and then the actual token which begins eyJ0ein this instance
    myHeaders.append("Authorization", "Bearer eyJ0e....[REDACTED TOKEN - LONG TOKEN TEXT HERE]");
    
    const requestOptions = {
      method: "GET",
      headers: myHeaders,
      redirect: "follow"
    };
    
    fetch("[Redacted URL of FLow]/triggers/manual/paths/invoke?api-version=2016-06-01&myURLvariablePassedToFlow=12345", requestOptions)
      .then((response) => response.text())
      .then((result) => console.log(result))
      .catch((error) => console.error(error));
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,591

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 64,090

Leaderboard