web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / "duplicate" How to cal...
Power Apps
Answered

"duplicate" How to call PA Flow with Javascript using current session?

(1) ShareShare
ReportReport
Posted on by 264

Hello, my friends!

It's "duplicate". PA Comunity didn't answer me.

 

Model Driven App, PowerAutomate Flow, only "Any user in my tenant" can trigger the flow.

This code works for "Anyone", but doesn't for "Any user in my tenant".

 let reg = new XMLHttpRequest();
 reg.open("POST", envVarRes.Value, true);
 reg.setRequestHeader('Content-Type', 'application/json');
 reg.send(JSON.stringify(data));

So in this case I have to use App registrations. It's not a safe way, anybody can debug and catch the secret.

 

Is there a way to use the current user session? Maybe Xrm.WebApi.online.execute(Something)?

or maybe I need to use "Cookies"? But I haven't figured out how to use cookies for Power App.

 

I have the same question (0)
  • Verified answer
    a33ik Profile Picture
    3,306 Most Valuable Professional on at

    Hello,

    That's not exactly the answer that you are looking for but when I have a need to "hide" something like this I place the call to the serverside - inside the plugin that handles "Custom API" message.

  • Max77 Profile Picture
    264 on at

    Thank you @a33ik ! It is sure  I will use this way. The only issue of Custom API  is  - It takes a lot of time to run first time (sometimes 10 sec). Maybe you know.. Does Custom API have a direct/clear method to work with SharePoint?

  • a33ik Profile Picture
    3,306 Most Valuable Professional on at

    I believe that natively Custom API can talk to Dataverse only. So I don't think there is a direct way to talk to Sharepoint.

  • owork138 Profile Picture
    20 on at

    To call a Public API (PA) flow in JavaScript using the current session, you'll typically need to follow a few steps. This depends on the specifics of the application and the Public API, but a general approach is:

    1. Authentication: Ensure that the current session has a valid authentication token to access the API. This could be stored in a session, local storage, or as a cookie.

    2. API Call: Use fetch or an alternative HTTP client (e.g., Axios) to make an HTTP request to the API. Make sure to include the authentication token in the headers.

      Here's a basic example using fetch:

       

      javascript
      Copy code
      // Get the authentication token (replace 'authToken' with your actual key) const authToken = sessionStorage.getItem('authToken') || localStorage.getItem('authToken'); // URL of the PA Flow API endpoint const apiUrl = 'https://api.example.com/pa-flow'; // Create headers, including authorization token const headers = { 'Content-Type': 'application/json', 'Authorization': `Bearer ${authToken}` }; // Example data to send (depends on the specific API) const requestData = { key1: 'value1', key2: 'value2' }; // Make the API request using fetch fetch(apiUrl, { method: 'POST', headers: headers, body: JSON.stringify(requestData) }) .then(response => response.json()) .then(data => { console.log('Success:', data); }) .catch(error => { console.error('Error:', error); });
       

      Key Notes:

      • Replace authToken and apiUrl with your actual authentication token and API endpoint URL.
      • Modify requestData according to the requirements of the specific Public API.
      • If your API uses another method (GET, PUT, etc.), update the method parameter accordingly.
      • Make sure your authentication token is kept secure and your app is protected against potential vulnerabilities like XSS and CSRF.  Libgen

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 711 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 319 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard